@autorest/python 5.14.0 → 5.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/ChangeLog.md +91 -2
  2. package/README.md +30 -4
  3. package/autorest/__init__.py +2 -3
  4. package/autorest/black/__init__.py +12 -5
  5. package/autorest/codegen/__init__.py +130 -179
  6. package/autorest/codegen/models/__init__.py +122 -78
  7. package/autorest/codegen/models/base_builder.py +70 -72
  8. package/autorest/codegen/models/base_model.py +7 -5
  9. package/autorest/codegen/models/{base_schema.py → base_type.py} +62 -49
  10. package/autorest/codegen/models/client.py +195 -36
  11. package/autorest/codegen/models/code_model.py +165 -299
  12. package/autorest/codegen/models/combined_type.py +107 -0
  13. package/autorest/codegen/models/constant_type.py +122 -0
  14. package/autorest/codegen/models/credential_types.py +224 -0
  15. package/autorest/codegen/models/dictionary_type.py +116 -0
  16. package/autorest/codegen/models/enum_type.py +195 -0
  17. package/autorest/codegen/models/imports.py +95 -41
  18. package/autorest/codegen/models/list_type.py +134 -0
  19. package/autorest/codegen/models/lro_operation.py +90 -133
  20. package/autorest/codegen/models/lro_paging_operation.py +28 -12
  21. package/autorest/codegen/models/model_type.py +239 -0
  22. package/autorest/codegen/models/operation.py +415 -241
  23. package/autorest/codegen/models/operation_group.py +82 -88
  24. package/autorest/codegen/models/paging_operation.py +101 -117
  25. package/autorest/codegen/models/parameter.py +307 -322
  26. package/autorest/codegen/models/parameter_list.py +366 -357
  27. package/autorest/codegen/models/primitive_types.py +544 -0
  28. package/autorest/codegen/models/property.py +122 -134
  29. package/autorest/codegen/models/request_builder.py +138 -86
  30. package/autorest/codegen/models/request_builder_parameter.py +122 -79
  31. package/autorest/codegen/models/response.py +325 -0
  32. package/autorest/codegen/models/utils.py +17 -1
  33. package/autorest/codegen/serializers/__init__.py +242 -118
  34. package/autorest/codegen/serializers/builder_serializer.py +863 -1027
  35. package/autorest/codegen/serializers/client_serializer.py +148 -82
  36. package/autorest/codegen/serializers/general_serializer.py +44 -47
  37. package/autorest/codegen/serializers/import_serializer.py +96 -31
  38. package/autorest/codegen/serializers/metadata_serializer.py +39 -79
  39. package/autorest/codegen/serializers/model_base_serializer.py +65 -29
  40. package/autorest/codegen/serializers/model_generic_serializer.py +9 -10
  41. package/autorest/codegen/serializers/model_init_serializer.py +4 -2
  42. package/autorest/codegen/serializers/model_python3_serializer.py +29 -22
  43. package/autorest/codegen/serializers/operation_groups_serializer.py +21 -18
  44. package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
  45. package/autorest/codegen/serializers/parameter_serializer.py +174 -0
  46. package/autorest/codegen/serializers/patch_serializer.py +14 -2
  47. package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
  48. package/autorest/codegen/serializers/utils.py +0 -103
  49. package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
  50. package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
  51. package/autorest/codegen/templates/config.py.jinja2 +13 -13
  52. package/autorest/codegen/templates/enum.py.jinja2 +4 -4
  53. package/autorest/codegen/templates/enum_container.py.jinja2 +1 -2
  54. package/autorest/codegen/templates/init.py.jinja2 +9 -6
  55. package/autorest/codegen/templates/keywords.jinja2 +14 -1
  56. package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
  57. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
  58. package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
  59. package/autorest/codegen/templates/model.py.jinja2 +23 -29
  60. package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
  61. package/autorest/codegen/templates/model_init.py.jinja2 +9 -8
  62. package/autorest/codegen/templates/operation.py.jinja2 +10 -15
  63. package/autorest/codegen/templates/operation_group.py.jinja2 +14 -13
  64. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -2
  65. package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
  66. package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
  67. package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
  68. package/autorest/codegen/templates/patch.py.jinja2 +18 -29
  69. package/autorest/codegen/templates/request_builder.py.jinja2 +20 -13
  70. package/autorest/codegen/templates/setup.py.jinja2 +9 -3
  71. package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
  72. package/autorest/jsonrpc/__init__.py +7 -12
  73. package/autorest/jsonrpc/localapi.py +4 -3
  74. package/autorest/jsonrpc/server.py +28 -9
  75. package/autorest/jsonrpc/stdstream.py +13 -6
  76. package/autorest/m2r/__init__.py +5 -8
  77. package/autorest/m4reformatter/__init__.py +1108 -0
  78. package/autorest/multiapi/__init__.py +24 -14
  79. package/autorest/multiapi/models/client.py +21 -11
  80. package/autorest/multiapi/models/code_model.py +23 -10
  81. package/autorest/multiapi/models/config.py +4 -1
  82. package/autorest/multiapi/models/constant_global_parameter.py +1 -0
  83. package/autorest/multiapi/models/global_parameter.py +2 -1
  84. package/autorest/multiapi/models/global_parameters.py +14 -8
  85. package/autorest/multiapi/models/imports.py +35 -18
  86. package/autorest/multiapi/models/mixin_operation.py +5 -5
  87. package/autorest/multiapi/models/operation_group.py +2 -1
  88. package/autorest/multiapi/models/operation_mixin_group.py +21 -10
  89. package/autorest/multiapi/serializers/__init__.py +20 -25
  90. package/autorest/multiapi/serializers/import_serializer.py +47 -15
  91. package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
  92. package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
  93. package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
  94. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
  95. package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
  96. package/autorest/multiapi/utils.py +3 -3
  97. package/autorest/postprocess/__init__.py +202 -0
  98. package/autorest/postprocess/get_all.py +19 -0
  99. package/autorest/postprocess/venvtools.py +73 -0
  100. package/autorest/preprocess/__init__.py +209 -0
  101. package/autorest/preprocess/helpers.py +54 -0
  102. package/autorest/{namer → preprocess}/python_mappings.py +25 -32
  103. package/package.json +3 -3
  104. package/run-python3.js +2 -3
  105. package/venvtools.py +1 -1
  106. package/autorest/codegen/models/constant_schema.py +0 -97
  107. package/autorest/codegen/models/credential_schema.py +0 -90
  108. package/autorest/codegen/models/credential_schema_policy.py +0 -77
  109. package/autorest/codegen/models/dictionary_schema.py +0 -103
  110. package/autorest/codegen/models/enum_schema.py +0 -246
  111. package/autorest/codegen/models/list_schema.py +0 -113
  112. package/autorest/codegen/models/object_schema.py +0 -249
  113. package/autorest/codegen/models/primitive_schemas.py +0 -476
  114. package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
  115. package/autorest/codegen/models/rest.py +0 -42
  116. package/autorest/codegen/models/schema_request.py +0 -45
  117. package/autorest/codegen/models/schema_response.py +0 -123
  118. package/autorest/codegen/serializers/rest_serializer.py +0 -57
  119. package/autorest/namer/__init__.py +0 -25
  120. package/autorest/namer/name_converter.py +0 -412
@@ -3,120 +3,164 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import Any, Dict
6
+ from typing import Any, Dict, Union
7
7
  from .base_model import BaseModel
8
8
  from .code_model import CodeModel
9
- from .credential_schema import AzureKeyCredentialSchema, TokenCredentialSchema
10
- from .object_schema import ObjectSchema, get_object_schema, HiddenModelObjectSchema
11
- from .dictionary_schema import DictionarySchema
12
- from .list_schema import ListSchema
13
- from .primitive_schemas import get_primitive_schema, AnySchema, PrimitiveSchema, IOSchema
14
- from .enum_schema import EnumSchema, HiddenModelEnumSchema, get_enum_schema
15
- from .base_schema import BaseSchema
16
- from .constant_schema import ConstantSchema
9
+ from .model_type import ModelType
10
+ from .dictionary_type import DictionaryType
11
+ from .list_type import ListType
12
+ from .combined_type import CombinedType
13
+ from .primitive_types import (
14
+ ByteArraySchema,
15
+ DateType,
16
+ DatetimeType,
17
+ DurationType,
18
+ IntegerType,
19
+ FloatType,
20
+ StringType,
21
+ TimeType,
22
+ AnyType,
23
+ PrimitiveType,
24
+ BinaryType,
25
+ BooleanType,
26
+ AnyObjectType,
27
+ UnixTimeType,
28
+ )
29
+ from .enum_type import EnumType
30
+ from .base_type import BaseType
31
+ from .constant_type import ConstantType
17
32
  from .imports import FileImport, ImportType, TypingSection
18
33
  from .lro_operation import LROOperation
19
34
  from .paging_operation import PagingOperation
20
- from .parameter import Parameter, ParameterStyle, ParameterLocation
35
+ from .parameter import (
36
+ Parameter,
37
+ ParameterMethodLocation,
38
+ ParameterLocation,
39
+ BodyParameter,
40
+ ParameterDelimeter,
41
+ MultipartBodyParameter,
42
+ ClientParameter,
43
+ ConfigParameter,
44
+ )
21
45
  from .operation import Operation
22
46
  from .property import Property
23
47
  from .operation_group import OperationGroup
24
- from .schema_response import SchemaResponse
25
- from .parameter_list import ParameterList, GlobalParameterList
26
- from .request_builder import RequestBuilder
48
+ from .response import Response
49
+ from .parameter_list import (
50
+ ParameterList,
51
+ ClientGlobalParameterList,
52
+ ConfigGlobalParameterList,
53
+ )
54
+ from .request_builder import (
55
+ RequestBuilder,
56
+ OverloadedRequestBuilder,
57
+ RequestBuilderBase,
58
+ )
27
59
  from .base_builder import BaseBuilder
28
60
  from .lro_paging_operation import LROPagingOperation
29
- from .request_builder_parameter import RequestBuilderParameter
30
- from .schema_request import SchemaRequest
61
+ from .request_builder_parameter import (
62
+ RequestBuilderParameter,
63
+ RequestBuilderBodyParameter,
64
+ )
65
+ from .credential_types import (
66
+ TokenCredentialType,
67
+ AzureKeyCredentialType,
68
+ ARMChallengeAuthenticationPolicyType,
69
+ BearerTokenCredentialPolicyType,
70
+ AzureKeyCredentialPolicyType,
71
+ CredentialType,
72
+ )
31
73
 
32
74
  __all__ = [
33
- "AzureKeyCredentialSchema",
34
- "AnySchema",
75
+ "AzureKeyCredentialPolicyType",
76
+ "AnyType",
35
77
  "BaseModel",
36
- "BaseSchema",
78
+ "BaseType",
37
79
  "CodeModel",
38
- "ConstantSchema",
39
- "ObjectSchema",
40
- "DictionarySchema",
41
- "ListSchema",
42
- "EnumSchema",
43
- "HiddenModelEnumSchema",
80
+ "ConstantType",
81
+ "ModelType",
82
+ "DictionaryType",
83
+ "ListType",
84
+ "EnumType",
44
85
  "FileImport",
45
86
  "ImportType",
46
87
  "TypingSection",
47
- "PrimitiveSchema",
88
+ "PrimitiveType",
48
89
  "LROOperation",
49
90
  "Operation",
50
91
  "PagingOperation",
51
92
  "Parameter",
52
93
  "ParameterList",
53
- "ParameterLocation",
54
94
  "OperationGroup",
55
95
  "Property",
56
96
  "RequestBuilder",
57
- "SchemaResponse",
58
- "TokenCredentialSchema",
97
+ "Response",
98
+ "TokenCredentialType",
59
99
  "LROPagingOperation",
60
100
  "BaseBuilder",
61
- "SchemaRequest",
62
101
  "RequestBuilderParameter",
63
- "HiddenModelObjectSchema",
64
- "ParameterStyle",
65
- "IOSchema",
66
- "GlobalParameterList",
102
+ "BinaryType",
103
+ "ClientGlobalParameterList",
104
+ "ConfigGlobalParameterList",
105
+ "ParameterMethodLocation",
106
+ "ParameterLocation",
107
+ "OverloadedRequestBuilder",
108
+ "RequestBuilderBase",
109
+ "BodyParameter",
110
+ "RequestBuilderBodyParameter",
111
+ "ParameterDelimeter",
112
+ "MultipartBodyParameter",
113
+ "CredentialType",
114
+ "ClientParameter",
115
+ "ConfigParameter",
67
116
  ]
68
117
 
69
- def _generate_as_object_schema(yaml_data: Dict[str, Any]) -> bool:
70
- if (
71
- yaml_data.get('properties') or
72
- yaml_data.get('discriminator') or
73
- yaml_data.get('parents') and yaml_data['parents'].get('immediate')
74
- ):
75
- return True
76
- return False
118
+ TYPE_TO_OBJECT = {
119
+ "integer": IntegerType,
120
+ "float": FloatType,
121
+ "string": StringType,
122
+ "list": ListType,
123
+ "dict": DictionaryType,
124
+ "constant": ConstantType,
125
+ "enum": EnumType,
126
+ "binary": BinaryType,
127
+ "any": AnyType,
128
+ "datetime": DatetimeType,
129
+ "time": TimeType,
130
+ "duration": DurationType,
131
+ "date": DateType,
132
+ "byte-array": ByteArraySchema,
133
+ "boolean": BooleanType,
134
+ "combined": CombinedType,
135
+ "OAuth2": TokenCredentialType,
136
+ "Key": AzureKeyCredentialType,
137
+ "ARMChallengeAuthenticationPolicy": ARMChallengeAuthenticationPolicyType,
138
+ "BearerTokenCredentialPolicy": BearerTokenCredentialPolicyType,
139
+ "AzureKeyCredentialPolicy": AzureKeyCredentialPolicyType,
140
+ "any-object": AnyObjectType,
141
+ "unixtime": UnixTimeType,
142
+ }
77
143
 
78
144
 
79
- def build_schema(yaml_data: Dict[str, Any], **kwargs) -> BaseSchema:
80
- code_model = kwargs.get("code_model", None)
81
- if not code_model:
82
- raise ValueError("CodeModel not passed through kwargs")
145
+ def build_type(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseType:
83
146
  yaml_id = id(yaml_data)
84
- namespace = code_model.namespace
85
147
  try:
86
- return code_model.lookup_schema(yaml_id)
148
+ return code_model.lookup_type(yaml_id)
87
149
  except KeyError:
88
150
  # Not created yet, let's create it and add it to the index
89
151
  pass
90
- schema: BaseSchema
91
- schema_type = yaml_data["type"]
92
- if schema_type == "constant":
93
- schema = ConstantSchema.from_yaml(namespace=namespace, yaml_data=yaml_data)
94
- code_model.primitives[yaml_id] = schema
95
-
96
- elif schema_type in ["choice", "sealed-choice"]:
97
- schema = get_enum_schema(code_model).from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
98
- code_model.enums[yaml_id] = schema
99
-
100
- elif schema_type == "array":
101
- schema = ListSchema.from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
102
- code_model.primitives[yaml_id] = schema
103
-
104
- elif schema_type == "dictionary":
105
- schema = DictionarySchema.from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
106
- code_model.primitives[yaml_id] = schema
107
-
108
- elif schema_type in ["object", "and", "group", "any-object"]:
109
- if _generate_as_object_schema(yaml_data):
110
- # To avoid infinite loop, create the right instance in memory,
111
- # put it in the index, and then parse the object.
112
- schema = get_object_schema(code_model)(namespace, yaml_data, "_", "")
113
- code_model.schemas[yaml_id] = schema
114
- schema.fill_instance_from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
115
- else:
116
- schema = AnySchema.from_yaml(namespace=namespace, yaml_data=yaml_data)
117
- code_model.primitives[yaml_id] = schema
152
+ if yaml_data["type"] == "model":
153
+ # need to special case model to avoid recursion
154
+ response = ModelType(yaml_data, code_model)
155
+ code_model.types_map[yaml_id] = response
156
+ response.fill_instance_from_yaml(yaml_data, code_model)
118
157
  else:
119
- schema = get_primitive_schema(namespace=namespace, yaml_data=yaml_data)
120
- code_model.primitives[yaml_id] = schema
158
+ response = TYPE_TO_OBJECT[yaml_data["type"]].from_yaml(yaml_data, code_model) # type: ignore
159
+ code_model.types_map[yaml_id] = response
160
+ return response
121
161
 
122
- return schema
162
+
163
+ RequestBuilderType = Union[RequestBuilder, OverloadedRequestBuilder]
164
+ ParameterType = Union[
165
+ Parameter, RequestBuilderParameter, ClientParameter, ConfigParameter
166
+ ]
@@ -3,95 +3,93 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import Any, Callable, Dict, List, Optional, Union
6
+ from abc import abstractmethod
7
+ from typing import Any, Dict, List, Optional, TypeVar, Union, TYPE_CHECKING, Generic
7
8
  from .base_model import BaseModel
8
- from .schema_response import SchemaResponse
9
- from .schema_request import SchemaRequest
9
+ from .parameter_list import (
10
+ ParameterList,
11
+ RequestBuilderParameterList,
12
+ OverloadedRequestBuilderParameterList,
13
+ )
10
14
 
15
+ ParameterListType = TypeVar(
16
+ "ParameterListType",
17
+ bound=Union[
18
+ ParameterList,
19
+ RequestBuilderParameterList,
20
+ OverloadedRequestBuilderParameterList,
21
+ ],
22
+ )
11
23
 
12
- _M4_HEADER_PARAMETERS = ["content_type", "accept"]
13
24
 
14
- def create_parameters(
15
- yaml_data: Dict[str, Any], code_model, parameter_creator: Callable
16
- ):
17
- multiple_requests = len(yaml_data["requests"]) > 1
25
+ if TYPE_CHECKING:
26
+ from .code_model import CodeModel
27
+ from .operation import Operation
28
+ from .request_builder import RequestBuilder
18
29
 
19
- multiple_content_type_parameters = []
20
- parameters = [
21
- parameter_creator(yaml, code_model=code_model)
22
- for yaml in yaml_data.get("parameters", [])
23
- ]
24
30
 
25
- for request in yaml_data["requests"]:
26
- for yaml in request.get("parameters", []):
27
- parameter = parameter_creator(yaml, code_model=code_model)
28
- name = yaml["language"]["python"]["name"]
29
- if name in _M4_HEADER_PARAMETERS:
30
- parameters.append(parameter)
31
- elif multiple_requests:
32
- parameter.has_multiple_content_types = True
33
- multiple_content_type_parameters.append(parameter)
34
- else:
35
- parameters.append(parameter)
36
-
37
- if multiple_content_type_parameters:
38
- body_parameters_name_set = set(
39
- p.serialized_name for p in multiple_content_type_parameters
40
- )
41
- if len(body_parameters_name_set) > 1:
42
- raise ValueError(
43
- f"The body parameter with multiple media types has different names: {body_parameters_name_set}"
44
- )
45
-
46
-
47
- parameters_index = {id(parameter.yaml_data): parameter for parameter in parameters}
48
-
49
- # Need to connect the groupBy and originalParameter
50
- for parameter in parameters:
51
- parameter_grouped_by_id = id(parameter.grouped_by)
52
- if parameter_grouped_by_id in parameters_index:
53
- parameter.grouped_by = parameters_index[parameter_grouped_by_id]
54
-
55
- parameter_original_id = id(parameter.original_parameter)
56
- if parameter_original_id in parameters_index:
57
- parameter.original_parameter = parameters_index[parameter_original_id]
58
-
59
- return parameters, multiple_content_type_parameters
60
-
61
- class BaseBuilder(BaseModel):
31
+ class BaseBuilder(Generic[ParameterListType], BaseModel):
62
32
  """Base class for Operations and Request Builders"""
63
33
 
64
34
  def __init__(
65
35
  self,
66
- code_model,
67
36
  yaml_data: Dict[str, Any],
37
+ code_model: "CodeModel",
68
38
  name: str,
69
- description: str,
70
- parameters,
71
- schema_requests: List[SchemaRequest],
72
- responses: Optional[List[SchemaResponse]] = None,
73
- summary: Optional[str] = None,
39
+ parameters: ParameterListType,
40
+ *,
41
+ overloads=None,
42
+ abstract: bool = False,
43
+ want_tracing: bool = True,
74
44
  ) -> None:
75
- super().__init__(yaml_data=yaml_data)
76
- self.code_model = code_model
45
+ super().__init__(yaml_data=yaml_data, code_model=code_model)
77
46
  self.name = name
78
- self.description = description
47
+ self._description: str = yaml_data.get("description", "")
79
48
  self.parameters = parameters
80
- self.responses = responses or []
81
- self.summary = summary
82
- self.schema_requests = schema_requests
49
+ self.overloads: Union[List["Operation"], List["RequestBuilder"]] = (
50
+ overloads or []
51
+ )
52
+ self._summary: str = yaml_data.get("summary", "")
53
+ # for operations where we don't know what to do, we mark them as abstract so users implement
54
+ # in patch.py
55
+ self.abstract = abstract
56
+ self.want_tracing = want_tracing
57
+ self.group_name: str = yaml_data["groupName"]
58
+ self.is_overload: bool = yaml_data["isOverload"]
59
+ self.api_versions: List[str] = yaml_data["apiVersions"]
83
60
 
84
61
  @property
85
- def default_content_type_declaration(self) -> str:
86
- return f'"{self.parameters.default_content_type}"'
62
+ def summary(self) -> Optional[str]:
63
+ if self.abstract:
64
+ return None
65
+ return self._summary
66
+
67
+ @property
68
+ def pylint_disable(self) -> str:
69
+ return ""
70
+
71
+ @abstractmethod
72
+ def response_type_annotation(self, **kwargs) -> str:
73
+ ...
74
+
75
+ @abstractmethod
76
+ def response_docstring_text(self, **kwargs) -> str:
77
+ ...
87
78
 
88
- def get_response_from_status(self, status_code: Optional[Union[str, int]]) -> SchemaResponse:
89
- for response in self.responses:
90
- if status_code in response.status_codes:
91
- return response
92
- raise ValueError(f"Incorrect status code {status_code}, operation {self.name}")
79
+ @abstractmethod
80
+ def response_docstring_type(self, **kwargs) -> str:
81
+ ...
93
82
 
94
83
  @property
95
- def success_status_code(self) -> List[Union[str, int]]:
96
- """The list of all successfull status code."""
97
- return [code for response in self.responses for code in response.status_codes if code != "default"]
84
+ def description(self) -> str:
85
+ if self.abstract:
86
+ return (
87
+ f'You need to write a custom operation for "{self.name}". Please refer to '
88
+ "https://aka.ms/azsdk/python/dpcodegen/python/customize to learn how to customize."
89
+ )
90
+ return self._description or self.name
91
+
92
+ def method_signature(self, is_python3_file: bool, async_mode: bool) -> List[str]:
93
+ if self.abstract:
94
+ return ["*args,", "**kwargs"]
95
+ return self.parameters.method_signature(is_python3_file, async_mode)
@@ -3,20 +3,22 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import Any, Dict
6
+ from typing import Any, Dict, TYPE_CHECKING
7
+
8
+ if TYPE_CHECKING:
9
+ from .code_model import CodeModel
7
10
 
8
11
 
9
12
  class BaseModel:
10
- """This is the base class for model that are based on some YAML data.
13
+ """This is the base class for model representations that are based on some YAML data.
11
14
 
12
15
  :param yaml_data: the yaml data for this schema
13
16
  :type yaml_data: dict[str, Any]
14
17
  """
15
18
 
16
- def __init__(
17
- self, yaml_data: Dict[str, Any],
18
- ) -> None:
19
+ def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
19
20
  self.yaml_data = yaml_data
21
+ self.code_model = code_model
20
22
 
21
23
  @property
22
24
  def id(self) -> int:
@@ -4,40 +4,51 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  from abc import ABC, abstractmethod
7
- from typing import Any, Dict, List, Optional, Union
7
+ from typing import Any, Dict, List, Optional, TYPE_CHECKING
8
8
 
9
9
  from .base_model import BaseModel
10
10
  from .imports import FileImport
11
11
 
12
+ if TYPE_CHECKING:
13
+ from .code_model import CodeModel
12
14
 
13
- class BaseSchema(BaseModel, ABC):
14
- """This is the base class for all schema models.
15
+
16
+ class BaseType(BaseModel, ABC):
17
+ """This is the base class for all types.
15
18
 
16
19
  :param yaml_data: the yaml data for this schema
17
20
  :type yaml_data: dict[str, Any]
18
21
  """
19
22
 
20
- def __init__(self, namespace: str, yaml_data: Dict[str, Any]) -> None:
21
- super().__init__(yaml_data)
22
- self.namespace = namespace
23
- self.default_value = yaml_data.get("defaultValue", None)
24
- self.xml_metadata = yaml_data.get("serialization", {}).get("xml", {})
25
- self.api_versions = set(value_dict["version"] for value_dict in yaml_data.get("apiVersions", []))
23
+ def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
24
+ super().__init__(yaml_data, code_model)
25
+ self.type = yaml_data["type"] # the type discriminator
26
+ self.api_versions: List[str] = yaml_data.get(
27
+ "apiVersions", []
28
+ ) # api versions this type is in.
26
29
 
27
30
  @classmethod
28
31
  def from_yaml(
29
- cls, namespace: str, yaml_data: Dict[str, Any], **kwargs # pylint: disable=unused-argument
30
- ) -> "BaseSchema":
31
- return cls(namespace=namespace, yaml_data=yaml_data)
32
+ cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
33
+ ) -> "BaseType":
34
+ return cls(yaml_data=yaml_data, code_model=code_model)
35
+
36
+ def imports( # pylint: disable=no-self-use
37
+ self, **kwargs # pylint: disable=unused-argument
38
+ ) -> FileImport:
39
+ return FileImport()
32
40
 
33
41
  @property
34
- def extra_description_information(self) -> str:
35
- return ""
42
+ def xml_metadata(self) -> Dict[str, Any]:
43
+ """XML metadata for the type, if the type has it."""
44
+ return self.yaml_data.get("xmlMetadata", {})
36
45
 
37
46
  @property
38
- def has_xml_serialization_ctxt(self) -> bool:
47
+ def is_xml(self) -> bool:
48
+ """Whether the type is an XML type or not. Most likely not."""
39
49
  return bool(self.xml_metadata)
40
50
 
51
+ @property
41
52
  def xml_serialization_ctxt(self) -> Optional[str]:
42
53
  """Return the serialization context in case this schema is used in an operation."""
43
54
  attrs_list = []
@@ -53,12 +64,6 @@ class BaseSchema(BaseModel, ABC):
53
64
  attrs_list.append(f"'text': True")
54
65
  return ", ".join(attrs_list)
55
66
 
56
- def imports(self) -> FileImport: # pylint: disable=no-self-use
57
- return FileImport()
58
-
59
- def model_file_imports(self) -> FileImport:
60
- return self.imports()
61
-
62
67
  @property
63
68
  @abstractmethod
64
69
  def serialization_type(self) -> str:
@@ -75,23 +80,30 @@ class BaseSchema(BaseModel, ABC):
75
80
  ...
76
81
 
77
82
  @property
83
+ def client_default_value(self) -> Any:
84
+ """Whether there's a client default value for this type"""
85
+ return self.yaml_data.get("clientDefaultValue")
86
+
78
87
  @abstractmethod
79
- def docstring_text(self) -> str:
80
- """The names used in rtype documentation
81
- """
88
+ def description(self, *, is_operation_file: bool) -> str:
89
+ """The description"""
82
90
  ...
83
91
 
84
- @property
85
92
  @abstractmethod
86
- def docstring_type(self) -> str:
93
+ def docstring_text(self, **kwargs: Any) -> str:
94
+ """The names used in rtype documentation"""
95
+ ...
96
+
97
+ @abstractmethod
98
+ def docstring_type(self, **kwargs: Any) -> str:
87
99
  """The python type used for RST syntax input.
88
100
 
89
101
  Special case for enum, for instance: 'str or ~namespace.EnumName'
90
102
  """
91
103
  ...
92
104
 
93
- @property
94
- def type_annotation(self) -> str:
105
+ @abstractmethod
106
+ def type_annotation(self, **kwargs: Any) -> str:
95
107
  """The python type used for type annotation
96
108
 
97
109
  Special case for enum, for instance: Union[str, "EnumName"]
@@ -99,8 +111,13 @@ class BaseSchema(BaseModel, ABC):
99
111
  ...
100
112
 
101
113
  @property
102
- def operation_type_annotation(self) -> str:
103
- return self.type_annotation
114
+ def validation(self) -> Optional[Dict[str, Any]]:
115
+ """Whether there's any validation constraints on this type.
116
+
117
+ Even though we generate validation maps if there are validation constraints,
118
+ only SDKs with client-side-validate=true (0.001% libraries, if any) actually raise in this case.
119
+ """
120
+ return None
104
121
 
105
122
  def get_declaration(self, value: Any) -> str: # pylint: disable=no-self-use
106
123
  """Return the current value from YAML as a Python string that represents the constant.
@@ -115,28 +132,24 @@ class BaseSchema(BaseModel, ABC):
115
132
  """
116
133
  return str(value)
117
134
 
118
- @property
119
- def default_value_declaration(self) -> str:
120
- """Return the default value as string using get_declaration.
121
- """
122
- if self.default_value is None:
123
- return "None"
124
- return self.get_declaration(self.default_value)
125
-
126
- @property
127
- def validation_map(self) -> Optional[Dict[str, Union[bool, int, str]]]: # pylint: disable=no-self-use
128
- return None
129
-
130
- @property
131
- def serialization_constraints(self) -> Optional[List[str]]: # pylint: disable=no-self-use
132
- return None
133
-
134
135
  @abstractmethod
135
- def get_json_template_representation(self, **kwargs: Any) -> Any:
136
+ def get_json_template_representation(
137
+ self,
138
+ *,
139
+ optional: bool = True,
140
+ client_default_value_declaration: Optional[str] = None,
141
+ description: Optional[str] = None,
142
+ ) -> Any:
136
143
  """Template of what this schema would look like as JSON input"""
137
144
  ...
138
145
 
146
+ @property
139
147
  @abstractmethod
140
- def get_files_and_data_template_representation(self, **kwargs: Any) -> Any:
141
- """Template of what this schema would look like as files input"""
148
+ def instance_check_template(self) -> str:
149
+ """Template of what an instance check of a variable for this type would look like"""
142
150
  ...
151
+
152
+ @property
153
+ def serialization_constraints(self) -> List[str]:
154
+ """Whether there are any serialization constraints when serializing this type."""
155
+ return []