@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
@@ -1,249 +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
- @property
43
- def type_annotation(self) -> str:
44
- return f'"{self.name}"'
45
-
46
- @property
47
- def operation_type_annotation(self) -> str:
48
- return f'"_models.{self.name}"'
49
-
50
- @property
51
- def docstring_type(self) -> str:
52
- return f"~{self.namespace}.models.{self.name}"
53
-
54
- @property
55
- def docstring_text(self) -> str:
56
- return self.name
57
-
58
- def get_declaration(self, value: Any) -> str:
59
- return f"{self.name}()"
60
-
61
- def __repr__(self) -> str:
62
- return f"<{self.__class__.__name__} {self.name}>"
63
-
64
- @property
65
- def has_xml_serialization_ctxt(self) -> bool:
66
- return False
67
-
68
- def xml_serialization_ctxt(self) -> Optional[str]:
69
- # object schema contains _xml_map, they don't need serialization context
70
- return ""
71
-
72
- def xml_map_content(self) -> Optional[str]:
73
- if not self.xml_metadata:
74
- raise ValueError("This object does not contain XML metadata")
75
- # This is NOT an error on the super call, we use the serialization context for "xml_map",
76
- # but we don't want to write a serialization context for an object.
77
- return super().xml_serialization_ctxt()
78
-
79
- def get_json_template_representation(self, **kwargs: Any) -> Any:
80
- if self._created_json_template_representation:
81
- return "..." # do this to avoid loop
82
- self._created_json_template_representation = True
83
- # don't add additional properties, because there's not really a concept of
84
- # additional properties in the template
85
- representation = {
86
- f'"{prop.original_swagger_name}"': prop.get_json_template_representation(**kwargs)
87
- for prop in [
88
- p for p in self.properties
89
- if not (p.is_discriminator or p.name == "additional_properties")
90
- ]
91
- }
92
- try:
93
- # add discriminator prop if there is one
94
- discriminator = next(p for p in self.properties if p.is_discriminator)
95
- representation[
96
- discriminator.original_swagger_name
97
- ] = self.discriminator_value or discriminator.original_swagger_name
98
- except StopIteration:
99
- pass
100
-
101
- # once we've finished, we want to reset created_json_template_representation to false
102
- # so we can call it again
103
- self._created_json_template_representation = False
104
- return representation
105
-
106
- def get_files_and_data_template_representation(self, **kwargs: Any) -> Any:
107
- object_schema_names = kwargs.get("object_schema_names", [])
108
- object_schema_names.append(self.name) # do tis to avoid circular
109
- kwargs["object_schema_names"] = object_schema_names
110
- return {
111
- "{}".format(
112
- prop.original_swagger_name
113
- ): prop.get_files_and_data_template_representation(**kwargs)
114
- for prop in self.properties
115
- }
116
-
117
-
118
- @classmethod
119
- def from_yaml(cls, namespace: str, yaml_data: Dict[str, Any], **kwargs) -> "ObjectSchema":
120
- """Returns a ClassType from the dict object constructed from a yaml file.
121
-
122
- WARNING: This guy might create an infinite loop.
123
-
124
- :param str name: The name of the class type.
125
- :param yaml_data: A representation of the schema of a class type from a yaml file.
126
- :type yaml_data: dict(str, str)
127
- :returns: A ClassType.
128
- :rtype: ~autorest.models.schema.ClassType
129
- """
130
- obj = cls(namespace, yaml_data, "", description="")
131
- obj.fill_instance_from_yaml(namespace, yaml_data)
132
- return obj
133
-
134
- def fill_instance_from_yaml(self, namespace: str, yaml_data: Dict[str, Any], **kwargs) -> None:
135
- properties = []
136
- base_models = []
137
-
138
- name = yaml_data["language"]["python"]["name"]
139
-
140
- # checking to see if there is a parent class and / or additional properties
141
- if yaml_data.get("parents"):
142
- immediate_parents = yaml_data["parents"]["immediate"]
143
- # checking if object has a parent
144
- if immediate_parents:
145
- for immediate_parent in immediate_parents:
146
- if immediate_parent["type"] == "dictionary":
147
- additional_properties_schema = DictionarySchema.from_yaml(
148
- namespace=namespace, yaml_data=immediate_parent, **kwargs
149
- )
150
- properties.append(
151
- Property(
152
- name="additional_properties",
153
- schema=additional_properties_schema,
154
- original_swagger_name="",
155
- yaml_data={},
156
- description="Unmatched properties from the message are deserialized to this collection."
157
- )
158
- )
159
- elif (
160
- immediate_parent["language"]["default"]["name"] != name and
161
- immediate_parent['type'] == "object"
162
- ):
163
- base_models.append(id(immediate_parent))
164
-
165
- # checking to see if this is a polymorphic class
166
- subtype_map = None
167
- if yaml_data.get("discriminator"):
168
- subtype_map = {}
169
- # map of discriminator value to child's name
170
- for children_yaml in yaml_data["discriminator"]["immediate"].values():
171
- subtype_map[children_yaml["discriminatorValue"]] = children_yaml["language"]["python"]["name"]
172
- if yaml_data.get("properties"):
173
- properties += [
174
- Property.from_yaml(p, has_additional_properties=len(properties) > 0, **kwargs)
175
- for p in yaml_data["properties"]
176
- ]
177
- # this is to ensure that the attribute map type and property type are generated correctly
178
-
179
-
180
-
181
- description = yaml_data["language"]["python"]["description"]
182
- is_exception = False
183
- exceptions_set = kwargs.pop("exceptions_set", None)
184
- if exceptions_set:
185
- if id(yaml_data) in exceptions_set:
186
- is_exception = True
187
-
188
- self.yaml_data = yaml_data
189
- self.name = name
190
- self.description = description
191
- self.properties = properties
192
- self.base_models = base_models
193
- self.is_exception = is_exception
194
- self.subtype_map = subtype_map
195
- self.discriminator_name = (
196
- yaml_data["discriminator"]["property"]["language"]["python"]["name"]
197
- if yaml_data.get("discriminator")
198
- else None
199
- )
200
- self.discriminator_value = yaml_data.get("discriminatorValue", None)
201
-
202
- @property
203
- def has_readonly_or_constant_property(self) -> bool:
204
- return any(x.readonly or x.constant for x in self.properties)
205
-
206
- @property
207
- def property_with_discriminator(self) -> Any:
208
- try:
209
- return next(p for p in self.properties if getattr(p.schema, "discriminator_name", None))
210
- except StopIteration:
211
- return None
212
-
213
- def imports(self) -> FileImport:
214
- file_import = FileImport()
215
- if self.is_exception:
216
- file_import.add_submodule_import("azure.core.exceptions", "HttpResponseError", ImportType.AZURECORE)
217
- return file_import
218
-
219
- class HiddenModelObjectSchema(ObjectSchema):
220
-
221
- @property
222
- def serialization_type(self) -> str:
223
- return "object"
224
-
225
- @property
226
- def type_annotation(self) -> str:
227
- return "JSONType"
228
-
229
- @property
230
- def operation_type_annotation(self) -> str:
231
- return "JSONType"
232
-
233
- @property
234
- def docstring_type(self) -> str:
235
- return "JSONType"
236
-
237
- @property
238
- def docstring_text(self) -> str:
239
- return "JSON object"
240
-
241
- def imports(self) -> FileImport:
242
- file_import = FileImport()
243
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
244
- return file_import
245
-
246
- def get_object_schema(code_model) -> Type[ObjectSchema]:
247
- if code_model.options["models_mode"]:
248
- return ObjectSchema
249
- return HiddenModelObjectSchema