Skip to content

Commit

Permalink
remove docs from json description (#2650)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft committed Jun 20, 2024
1 parent 72a8348 commit 679b4d8
Show file tree
Hide file tree
Showing 231 changed files with 15,729 additions and 22,801 deletions.
8 changes: 8 additions & 0 deletions .chronus/changes/remove_docs_from_json-2024-5-20-15-57-42.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: fix
packages:
- "@autorest/python"
- "@azure-tools/typespec-python"
---

fix sphinx rendering of json docs by removing comments
2 changes: 0 additions & 2 deletions packages/autorest.python/autorest/codegen/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ def get_declaration(self, value: Any) -> str:
def get_json_template_representation(
self,
*,
optional: bool = True,
client_default_value_declaration: Optional[str] = None,
description: Optional[str] = None,
) -> Any:
"""Template of what this schema would look like as JSON input"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,10 @@ def is_form_data(self) -> bool:
def get_json_template_representation(
self,
*,
optional: bool = True,
client_default_value_declaration: Optional[str] = None,
description: Optional[str] = None,
) -> Any:
return self.types[0].get_json_template_representation(
optional=optional,
client_default_value_declaration=client_default_value_declaration,
description=description,
)

def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,10 @@ def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "Const
def get_json_template_representation(
self,
*,
optional: bool = True,
# pylint: disable=unused-argument
client_default_value_declaration: Optional[str] = None,
description: Optional[str] = None,
) -> Any:
return self.value_type.get_json_template_representation(
optional=optional,
client_default_value_declaration=self.get_declaration(),
description=description,
)

def _imports_shared(self, **kwargs: Any):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ def description(self, *, is_operation_file: bool) -> str: # pylint: disable=unu
def get_json_template_representation(
self,
*,
optional: bool = True,
client_default_value_declaration: Optional[str] = None,
description: Optional[str] = None,
) -> Any:
raise TypeError("You should not try to get a JSON template representation of a CredentialSchema")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ def docstring_type(self, **kwargs: Any) -> str:
def get_json_template_representation(
self,
*,
optional: bool = True,
client_default_value_declaration: Optional[str] = None,
description: Optional[str] = None,
) -> Any:
return {
'"str"': self.element_type.get_json_template_representation(
optional=optional,
client_default_value_declaration=client_default_value_declaration,
description=description,
)
}

Expand Down
8 changes: 0 additions & 8 deletions packages/autorest.python/autorest/codegen/models/enum_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,11 @@ def docstring_type(self, **kwargs: Any) -> str:
def get_json_template_representation(
self,
*,
optional: bool = True,
client_default_value_declaration: Optional[str] = None,
description: Optional[str] = None,
) -> Any:
# for better display effect, use the only value instead of var type
return self.value_type.get_json_template_representation(
optional=optional,
client_default_value_declaration=client_default_value_declaration,
description=description,
)

@property
Expand Down Expand Up @@ -193,15 +189,11 @@ def docstring_type(self, **kwargs: Any) -> str:
def get_json_template_representation(
self,
*,
optional: bool = True,
client_default_value_declaration: Optional[str] = None,
description: Optional[str] = None,
) -> Any:
# for better display effect, use the only value instead of var type
return self.value_type.get_json_template_representation(
optional=optional,
client_default_value_declaration=client_default_value_declaration,
description=description,
)

@property
Expand Down
4 changes: 0 additions & 4 deletions packages/autorest.python/autorest/codegen/models/list_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,11 @@ def validation(self) -> Optional[Dict[str, Union[bool, int, str]]]:
def get_json_template_representation(
self,
*,
optional: bool = True,
client_default_value_declaration: Optional[str] = None,
description: Optional[str] = None,
) -> Any:
return [
self.element_type.get_json_template_representation(
optional=optional,
client_default_value_declaration=client_default_value_declaration,
description=description,
)
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ def discriminated_subtypes_name_mapping(self) -> Dict[str, str]:
def get_json_template_representation(
self,
*,
optional: bool = True,
client_default_value_declaration: Optional[str] = None,
description: Optional[str] = None,
) -> Any:
if self._created_json_template_representation:
return "..." # do this to avoid loop
Expand All @@ -163,9 +161,7 @@ def get_json_template_representation(
# additional properties in the template
representation = {
f'"{prop.wire_name}"': prop.get_json_template_representation(
optional=optional,
client_default_value_declaration=client_default_value_declaration,
description=description,
)
for prop in [
p for p in self.properties if not (p.is_discriminator or p.client_name == "additional_properties")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from .base import BaseType
from .imports import FileImport, ImportType, TypingSection
from .utils import add_to_description

if TYPE_CHECKING:
from .code_model import CodeModel
Expand All @@ -36,26 +35,13 @@ def docstring_text(self, **kwargs: Any) -> str:
def get_json_template_representation(
self,
*,
optional: bool = True,
client_default_value_declaration: Optional[str] = None,
description: Optional[str] = None,
) -> Any:
comment = ""
if optional:
comment = add_to_description(comment, "Optional.")
if self.client_default_value is not None:
client_default_value_declaration = client_default_value_declaration or self.get_declaration(
self.client_default_value
)
if client_default_value_declaration:
comment = add_to_description(comment, f"Default value is {client_default_value_declaration}.")
else:
client_default_value_declaration = self.default_template_representation_declaration
if description:
comment = add_to_description(comment, description)
if comment:
comment = f"# {comment}"
return client_default_value_declaration + ("" if self.code_model.for_test else comment)
return client_default_value_declaration or self.default_template_representation_declaration

@property
def default_template_representation_declaration(self) -> str:
Expand Down
7 changes: 0 additions & 7 deletions packages/autorest.python/autorest/codegen/models/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,16 @@ def get_declaration(self, value: Any = None) -> Any:
def get_json_template_representation(
self,
*,
optional: bool = True, # pylint: disable=unused-argument
client_default_value_declaration: Optional[str] = None,
description: Optional[str] = None,
) -> Any:
if self.is_multipart_file_input:
file_type_str = '"filetype"' if self.code_model.for_test else "filetype"
return f"[{file_type_str}]" if self.type.type == "list" else file_type_str
if self.client_default_value:
client_default_value_declaration = self.get_declaration(self.client_default_value)
if self.description(is_operation_file=True):
description = self.description(is_operation_file=True)
# make sure there is no \n otherwise the json template will be invalid
description = (description or "").replace("\n", " ")
return self.type.get_json_template_representation(
optional=self.optional,
client_default_value_declaration=client_default_value_declaration,
description=description,
)

def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,16 @@ def begin_basic_polling(
# JSON input template you can fill out and use as your body input.
product = {
"properties": {
"id": 0, # Optional.
"name": "str" # Optional.
"id": 0,
"name": "str"
}
}
# response body for status code(s): 200
response == {
"properties": {
"id": 0, # Optional.
"name": "str" # Optional.
"id": 0,
"name": "str"
}
}
"""
Expand All @@ -190,8 +190,8 @@ def begin_basic_polling(
# response body for status code(s): 200
response == {
"properties": {
"id": 0, # Optional.
"name": "str" # Optional.
"id": 0,
"name": "str"
}
}
"""
Expand All @@ -215,16 +215,16 @@ def begin_basic_polling(
# JSON input template you can fill out and use as your body input.
product = {
"properties": {
"id": 0, # Optional.
"name": "str" # Optional.
"id": 0,
"name": "str"
}
}
# response body for status code(s): 200
response == {
"properties": {
"id": 0, # Optional.
"name": "str" # Optional.
"id": 0,
"name": "str"
}
}
"""
Expand Down Expand Up @@ -287,8 +287,8 @@ def basic_paging(self, **kwargs: Any) -> Iterable[JSON]:
# response body for status code(s): 200
response == {
"properties": {
"id": 0, # Optional.
"name": "str" # Optional.
"id": 0,
"name": "str"
}
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ async def begin_basic_polling(
# JSON input template you can fill out and use as your body input.
product = {
"properties": {
"id": 0, # Optional.
"name": "str" # Optional.
"id": 0,
"name": "str"
}
}
# response body for status code(s): 200
response == {
"properties": {
"id": 0, # Optional.
"name": "str" # Optional.
"id": 0,
"name": "str"
}
}
"""
Expand All @@ -161,8 +161,8 @@ async def begin_basic_polling(
# response body for status code(s): 200
response == {
"properties": {
"id": 0, # Optional.
"name": "str" # Optional.
"id": 0,
"name": "str"
}
}
"""
Expand All @@ -186,16 +186,16 @@ async def begin_basic_polling(
# JSON input template you can fill out and use as your body input.
product = {
"properties": {
"id": 0, # Optional.
"name": "str" # Optional.
"id": 0,
"name": "str"
}
}
# response body for status code(s): 200
response == {
"properties": {
"id": 0, # Optional.
"name": "str" # Optional.
"id": 0,
"name": "str"
}
}
"""
Expand Down Expand Up @@ -262,8 +262,8 @@ def basic_paging(self, **kwargs: Any) -> AsyncIterable[JSON]:
# response body for status code(s): 200
response == {
"properties": {
"id": 0, # Optional.
"name": "str" # Optional.
"id": 0,
"name": "str"
}
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_report(self, *, qualifier: Optional[str] = None, **kwargs: Any) -> Dict[
# response body for status code(s): 200
response == {
"str": 0 # Optional.
"str": 0
}
"""
error_map: MutableMapping[int, Type[HttpResponseError]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def get_report(self, *, qualifier: Optional[str] = None, **kwargs: Any) ->
# response body for status code(s): 200
response == {
"str": 0 # Optional.
"str": 0
}
"""
error_map: MutableMapping[int, Type[HttpResponseError]] = {
Expand Down
Loading

0 comments on commit 679b4d8

Please sign in to comment.