@autorest/python 5.15.0 → 5.18.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 (118) hide show
  1. package/ChangeLog.md +98 -4
  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 +122 -211
  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} +68 -45
  10. package/autorest/codegen/models/client.py +193 -40
  11. package/autorest/codegen/models/code_model.py +145 -245
  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 +131 -0
  16. package/autorest/codegen/models/enum_type.py +195 -0
  17. package/autorest/codegen/models/imports.py +93 -41
  18. package/autorest/codegen/models/list_type.py +149 -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 +262 -0
  22. package/autorest/codegen/models/operation.py +412 -259
  23. package/autorest/codegen/models/operation_group.py +80 -91
  24. package/autorest/codegen/models/paging_operation.py +101 -117
  25. package/autorest/codegen/models/parameter.py +302 -341
  26. package/autorest/codegen/models/parameter_list.py +373 -357
  27. package/autorest/codegen/models/primitive_types.py +544 -0
  28. package/autorest/codegen/models/property.py +136 -134
  29. package/autorest/codegen/models/request_builder.py +138 -86
  30. package/autorest/codegen/models/request_builder_parameter.py +122 -86
  31. package/autorest/codegen/models/response.py +325 -0
  32. package/autorest/codegen/models/utils.py +13 -17
  33. package/autorest/codegen/serializers/__init__.py +212 -112
  34. package/autorest/codegen/serializers/builder_serializer.py +931 -1040
  35. package/autorest/codegen/serializers/client_serializer.py +140 -84
  36. package/autorest/codegen/serializers/general_serializer.py +26 -50
  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 +62 -34
  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 -19
  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 +4 -1
  47. package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
  48. package/autorest/codegen/serializers/utils.py +0 -126
  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 -1
  54. package/autorest/codegen/templates/init.py.jinja2 +3 -3
  55. package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
  56. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
  57. package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
  58. package/autorest/codegen/templates/model.py.jinja2 +23 -24
  59. package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
  60. package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
  61. package/autorest/codegen/templates/operation.py.jinja2 +10 -14
  62. package/autorest/codegen/templates/operation_group.py.jinja2 +9 -15
  63. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
  64. package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
  65. package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
  66. package/autorest/codegen/templates/request_builder.py.jinja2 +19 -10
  67. package/autorest/codegen/templates/setup.py.jinja2 +9 -3
  68. package/autorest/codegen/templates/vendor.py.jinja2 +1 -1
  69. package/autorest/jsonrpc/__init__.py +7 -12
  70. package/autorest/jsonrpc/localapi.py +4 -3
  71. package/autorest/jsonrpc/server.py +28 -9
  72. package/autorest/jsonrpc/stdstream.py +13 -6
  73. package/autorest/m2r/__init__.py +5 -8
  74. package/autorest/m4reformatter/__init__.py +1126 -0
  75. package/autorest/multiapi/__init__.py +24 -14
  76. package/autorest/multiapi/models/client.py +21 -11
  77. package/autorest/multiapi/models/code_model.py +23 -10
  78. package/autorest/multiapi/models/config.py +4 -1
  79. package/autorest/multiapi/models/constant_global_parameter.py +1 -0
  80. package/autorest/multiapi/models/global_parameter.py +2 -1
  81. package/autorest/multiapi/models/global_parameters.py +14 -8
  82. package/autorest/multiapi/models/imports.py +24 -17
  83. package/autorest/multiapi/models/mixin_operation.py +5 -5
  84. package/autorest/multiapi/models/operation_group.py +2 -1
  85. package/autorest/multiapi/models/operation_mixin_group.py +21 -10
  86. package/autorest/multiapi/serializers/__init__.py +20 -25
  87. package/autorest/multiapi/serializers/import_serializer.py +47 -17
  88. package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
  89. package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
  90. package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
  91. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
  92. package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
  93. package/autorest/multiapi/utils.py +3 -3
  94. package/autorest/postprocess/__init__.py +202 -0
  95. package/autorest/postprocess/get_all.py +19 -0
  96. package/autorest/postprocess/venvtools.py +73 -0
  97. package/autorest/preprocess/__init__.py +210 -0
  98. package/autorest/preprocess/helpers.py +54 -0
  99. package/autorest/{namer → preprocess}/python_mappings.py +25 -32
  100. package/package.json +3 -3
  101. package/run-python3.js +2 -3
  102. package/venvtools.py +1 -1
  103. package/autorest/codegen/models/constant_schema.py +0 -101
  104. package/autorest/codegen/models/credential_model.py +0 -47
  105. package/autorest/codegen/models/credential_schema.py +0 -91
  106. package/autorest/codegen/models/credential_schema_policy.py +0 -77
  107. package/autorest/codegen/models/dictionary_schema.py +0 -103
  108. package/autorest/codegen/models/enum_schema.py +0 -215
  109. package/autorest/codegen/models/list_schema.py +0 -123
  110. package/autorest/codegen/models/object_schema.py +0 -253
  111. package/autorest/codegen/models/primitive_schemas.py +0 -466
  112. package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
  113. package/autorest/codegen/models/rest.py +0 -42
  114. package/autorest/codegen/models/schema_request.py +0 -45
  115. package/autorest/codegen/models/schema_response.py +0 -136
  116. package/autorest/codegen/serializers/rest_serializer.py +0 -57
  117. package/autorest/namer/__init__.py +0 -25
  118. package/autorest/namer/name_converter.py +0 -412
@@ -1,253 +0,0 @@
1
- # -------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Corporation. All rights reserved.
3
- # Licensed under the MIT License. See License.txt in the project root for
4
- # license information.
5
- # --------------------------------------------------------------------------
6
- from typing import Any, Dict, List, Optional, Union, Type
7
- from .base_schema import BaseSchema
8
- from .dictionary_schema import DictionarySchema
9
- from .property import Property
10
- from .imports import FileImport, ImportType, TypingSection
11
-
12
-
13
- class ObjectSchema(BaseSchema): # pylint: disable=too-many-instance-attributes
14
- """Represents a class ready to be serialized in Python.
15
-
16
- :param str name: The name of the class.
17
- :param str description: The description of the class.
18
- :param properties: the optional properties of the class.
19
- :type properties: dict(str, str)
20
- """
21
-
22
- def __init__(
23
- self, namespace: str, yaml_data: Dict[str, Any], name: str, description: str = "", **kwargs
24
- ) -> None:
25
- super(ObjectSchema, self).__init__(namespace=namespace, yaml_data=yaml_data)
26
- self.name = name
27
- self.description = description
28
- self.max_properties: Optional[int] = kwargs.pop("max_properties", None)
29
- self.min_properties: Optional[int] = kwargs.pop("min_properties", None)
30
- self.properties: List[Property] = kwargs.pop("properties", [])
31
- self.is_exception: bool = kwargs.pop("is_exception", False)
32
- self.base_models: Union[List[int], List["ObjectSchema"]] = kwargs.pop("base_models", [])
33
- self.subtype_map: Optional[Dict[str, str]] = kwargs.pop("subtype_map", None)
34
- self.discriminator_name: Optional[str] = kwargs.pop("discriminator_name", None)
35
- self.discriminator_value: Optional[str] = kwargs.pop("discriminator_value", None)
36
- self._created_json_template_representation = False
37
-
38
- @property
39
- def serialization_type(self) -> str:
40
- return self.name
41
-
42
- def type_annotation(self, *, is_operation_file: bool = False) -> str:
43
- retval = f"_models.{self.name}"
44
- return retval if is_operation_file else f'"{retval}"'
45
-
46
- @property
47
- def docstring_type(self) -> str:
48
- return f"~{self.namespace}.models.{self.name}"
49
-
50
- @property
51
- def docstring_text(self) -> str:
52
- return self.name
53
-
54
- def get_declaration(self, value: Any) -> str:
55
- return f"{self.name}()"
56
-
57
- def __repr__(self) -> str:
58
- return f"<{self.__class__.__name__} {self.name}>"
59
-
60
- @property
61
- def has_xml_serialization_ctxt(self) -> bool:
62
- return False
63
-
64
- def xml_serialization_ctxt(self) -> Optional[str]:
65
- # object schema contains _xml_map, they don't need serialization context
66
- return ""
67
-
68
- def xml_map_content(self) -> Optional[str]:
69
- if not self.xml_metadata:
70
- raise ValueError("This object does not contain XML metadata")
71
- # This is NOT an error on the super call, we use the serialization context for "xml_map",
72
- # but we don't want to write a serialization context for an object.
73
- return super().xml_serialization_ctxt()
74
-
75
- def get_json_template_representation(self, **kwargs: Any) -> Any:
76
- if self._created_json_template_representation:
77
- return "..." # do this to avoid loop
78
- self._created_json_template_representation = True
79
- # don't add additional properties, because there's not really a concept of
80
- # additional properties in the template
81
- representation = {
82
- f'"{prop.original_swagger_name}"': prop.get_json_template_representation(**kwargs)
83
- for prop in [
84
- p for p in self.properties
85
- if not (p.is_discriminator or p.name == "additional_properties")
86
- ]
87
- }
88
- try:
89
- # add discriminator prop if there is one
90
- discriminator = next(p for p in self.properties if p.is_discriminator)
91
- representation[
92
- discriminator.original_swagger_name
93
- ] = self.discriminator_value or discriminator.original_swagger_name
94
- except StopIteration:
95
- pass
96
-
97
- # once we've finished, we want to reset created_json_template_representation to false
98
- # so we can call it again
99
- self._created_json_template_representation = False
100
- return representation
101
-
102
- def get_files_and_data_template_representation(self, **kwargs: Any) -> Any:
103
- object_schema_names = kwargs.get("object_schema_names", [])
104
- object_schema_names.append(self.name) # do tis to avoid circular
105
- kwargs["object_schema_names"] = object_schema_names
106
- return {
107
- "{}".format(
108
- prop.original_swagger_name
109
- ): prop.get_files_and_data_template_representation(**kwargs)
110
- for prop in self.properties
111
- }
112
-
113
-
114
- @classmethod
115
- def from_yaml(cls, namespace: str, yaml_data: Dict[str, Any], **kwargs) -> "ObjectSchema":
116
- """Returns a ClassType from the dict object constructed from a yaml file.
117
-
118
- WARNING: This guy might create an infinite loop.
119
-
120
- :param str name: The name of the class type.
121
- :param yaml_data: A representation of the schema of a class type from a yaml file.
122
- :type yaml_data: dict(str, str)
123
- :returns: A ClassType.
124
- :rtype: ~autorest.models.schema.ClassType
125
- """
126
- obj = cls(namespace, yaml_data, "", description="")
127
- obj.fill_instance_from_yaml(namespace, yaml_data)
128
- return obj
129
-
130
- def fill_instance_from_yaml(self, namespace: str, yaml_data: Dict[str, Any], **kwargs) -> None:
131
- properties = []
132
- base_models = []
133
-
134
- name = yaml_data["language"]["python"]["name"]
135
-
136
- # checking to see if there is a parent class and / or additional properties
137
- if yaml_data.get("parents"):
138
- immediate_parents = yaml_data["parents"]["immediate"]
139
- # checking if object has a parent
140
- if immediate_parents:
141
- for immediate_parent in immediate_parents:
142
- if immediate_parent["type"] == "dictionary":
143
- additional_properties_schema = DictionarySchema.from_yaml(
144
- namespace=namespace, yaml_data=immediate_parent, **kwargs
145
- )
146
- properties.append(
147
- Property(
148
- name="additional_properties",
149
- schema=additional_properties_schema,
150
- original_swagger_name="",
151
- yaml_data={},
152
- description="Unmatched properties from the message are deserialized to this collection."
153
- )
154
- )
155
- elif (
156
- immediate_parent["language"]["default"]["name"] != name and
157
- immediate_parent['type'] == "object"
158
- ):
159
- base_models.append(id(immediate_parent))
160
-
161
- # checking to see if this is a polymorphic class
162
- subtype_map = None
163
- if yaml_data.get("discriminator"):
164
- subtype_map = {}
165
- # map of discriminator value to child's name
166
- for children_yaml in yaml_data["discriminator"]["immediate"].values():
167
- subtype_map[children_yaml["discriminatorValue"]] = children_yaml["language"]["python"]["name"]
168
- if yaml_data.get("properties"):
169
- properties += [
170
- Property.from_yaml(p, has_additional_properties=len(properties) > 0, **kwargs)
171
- for p in yaml_data["properties"]
172
- ]
173
- # this is to ensure that the attribute map type and property type are generated correctly
174
-
175
-
176
-
177
- description = yaml_data["language"]["python"]["description"]
178
- is_exception = False
179
- exceptions_set = kwargs.pop("exceptions_set", None)
180
- if exceptions_set:
181
- if id(yaml_data) in exceptions_set:
182
- is_exception = True
183
-
184
- self.yaml_data = yaml_data
185
- self.name = name
186
- self.description = description
187
- self.properties = properties
188
- self.base_models = base_models
189
- self.is_exception = is_exception
190
- self.subtype_map = subtype_map
191
- self.discriminator_name = (
192
- yaml_data["discriminator"]["property"]["language"]["python"]["name"]
193
- if yaml_data.get("discriminator")
194
- else None
195
- )
196
- self.discriminator_value = yaml_data.get("discriminatorValue", None)
197
-
198
- @property
199
- def has_readonly_or_constant_property(self) -> bool:
200
- return any(x.readonly or x.constant for x in self.properties)
201
-
202
- @property
203
- def property_with_discriminator(self) -> Any:
204
- try:
205
- return next(p for p in self.properties if getattr(p.schema, "discriminator_name", None))
206
- except StopIteration:
207
- return None
208
-
209
- def imports(self) -> FileImport:
210
- file_import = FileImport()
211
- if self.is_exception:
212
- file_import.add_submodule_import("azure.core.exceptions", "HttpResponseError", ImportType.AZURECORE)
213
- return file_import
214
-
215
- def model_file_imports(self) -> FileImport:
216
- file_import = self.imports()
217
- file_import.add_import("__init__", ImportType.LOCAL, typing_section=TypingSection.TYPING, alias="_models")
218
- return file_import
219
-
220
- class HiddenModelObjectSchema(ObjectSchema):
221
-
222
- @property
223
- def serialization_type(self) -> str:
224
- return "object"
225
-
226
- def type_annotation(self, *, is_operation_file: bool = False) -> str: # pylint: disable=unused-argument
227
- if self.xml_metadata:
228
- return "ET.Element"
229
- return "JSONType"
230
-
231
- @property
232
- def docstring_type(self) -> str:
233
- if self.xml_metadata:
234
- return "ET.Element"
235
- return "JSONType"
236
-
237
- @property
238
- def docstring_text(self) -> str:
239
- if self.xml_metadata:
240
- return "XML Element"
241
- return "JSON object"
242
-
243
- def imports(self) -> FileImport:
244
- file_import = FileImport()
245
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
246
- if self.xml_metadata:
247
- file_import.add_submodule_import("xml.etree", "ElementTree", ImportType.STDLIB, alias="ET")
248
- return file_import
249
-
250
- def get_object_schema(code_model) -> Type[ObjectSchema]:
251
- if code_model.options["models_mode"]:
252
- return ObjectSchema
253
- return HiddenModelObjectSchema