@autorest/python 6.2.12 → 6.2.16
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.
- package/autorest/__init__.py +7 -5
- package/autorest/_utils.py +7 -1
- package/autorest/black/__init__.py +6 -1
- package/autorest/codegen/__init__.py +1 -1
- package/autorest/codegen/models/base.py +4 -13
- package/autorest/codegen/models/client.py +9 -11
- package/autorest/codegen/models/code_model.py +2 -2
- package/autorest/codegen/models/credential_types.py +7 -14
- package/autorest/codegen/models/dictionary_type.py +1 -1
- package/autorest/codegen/models/imports.py +3 -3
- package/autorest/codegen/models/lro_operation.py +5 -5
- package/autorest/codegen/models/model_type.py +11 -8
- package/autorest/codegen/models/operation.py +8 -8
- package/autorest/codegen/models/operation_group.py +3 -1
- package/autorest/codegen/models/paging_operation.py +2 -2
- package/autorest/codegen/models/parameter.py +27 -6
- package/autorest/codegen/models/parameter_list.py +1 -9
- package/autorest/codegen/models/primitive_types.py +1 -1
- package/autorest/codegen/models/property.py +15 -3
- package/autorest/codegen/models/response.py +2 -2
- package/autorest/codegen/serializers/__init__.py +2 -2
- package/autorest/codegen/serializers/builder_serializer.py +55 -25
- package/autorest/codegen/serializers/client_serializer.py +6 -4
- package/autorest/codegen/serializers/general_serializer.py +7 -2
- package/autorest/codegen/serializers/model_serializer.py +14 -4
- package/autorest/codegen/serializers/sample_serializer.py +2 -6
- package/autorest/codegen/templates/config.py.jinja2 +25 -6
- package/autorest/codegen/templates/enum.py.jinja2 +2 -2
- package/autorest/codegen/templates/metadata.json.jinja2 +18 -9
- package/autorest/codegen/templates/model_base.py.jinja2 +87 -70
- package/autorest/codegen/templates/model_dpg.py.jinja2 +6 -4
- package/autorest/codegen/templates/serialization.py.jinja2 +20 -15
- package/autorest/codegen/templates/vendor.py.jinja2 +3 -2
- package/autorest/jsonrpc/localapi.py +3 -3
- package/autorest/jsonrpc/server.py +3 -3
- package/autorest/m2r/__init__.py +1 -1
- package/autorest/m4reformatter/__init__.py +12 -2
- package/autorest/multiapi/models/__init__.py +2 -0
- package/autorest/multiapi/models/code_model.py +13 -0
- package/autorest/multiapi/models/global_parameter.py +1 -0
- package/autorest/multiapi/models/imports.py +3 -3
- package/autorest/multiapi/serializers/__init__.py +30 -3
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +8 -12
- package/autorest/postprocess/get_all.py +3 -1
- package/autorest/postprocess/venvtools.py +5 -4
- package/autorest/preprocess/__init__.py +16 -4
- package/autorest/preprocess/python_mappings.py +1 -0
- package/index.js +0 -0
- package/package.json +2 -1
- package/requirements.txt +6 -6
- package/setup.py +0 -1
- package/venvtools.py +2 -3
package/autorest/__init__.py
CHANGED
|
@@ -25,7 +25,9 @@ class ReaderAndWriter:
|
|
|
25
25
|
self._list_file: List[str] = []
|
|
26
26
|
try:
|
|
27
27
|
with open(
|
|
28
|
-
Path(self.output_folder) / Path("..") / Path("python.json"),
|
|
28
|
+
Path(self.output_folder) / Path("..") / Path("python.json"),
|
|
29
|
+
"r",
|
|
30
|
+
encoding="utf-8-sig",
|
|
29
31
|
) as fd:
|
|
30
32
|
python_json = json.load(fd)
|
|
31
33
|
except Exception: # pylint: disable=broad-except
|
|
@@ -41,7 +43,7 @@ class ReaderAndWriter:
|
|
|
41
43
|
"""Directly reading from disk"""
|
|
42
44
|
# make path relative to output folder
|
|
43
45
|
try:
|
|
44
|
-
with open(self.output_folder / Path(path), "r") as fd:
|
|
46
|
+
with open(self.output_folder / Path(path), "r", encoding="utf-8-sig") as fd:
|
|
45
47
|
return fd.read()
|
|
46
48
|
except FileNotFoundError:
|
|
47
49
|
return ""
|
|
@@ -51,7 +53,7 @@ class ReaderAndWriter:
|
|
|
51
53
|
file_folder = Path(filename).parent
|
|
52
54
|
if not Path.is_dir(self.output_folder / file_folder):
|
|
53
55
|
Path.mkdir(self.output_folder / file_folder, parents=True)
|
|
54
|
-
with open(self.output_folder / Path(filename), "w") as fd:
|
|
56
|
+
with open(self.output_folder / Path(filename), "w", encoding="utf-8") as fd:
|
|
55
57
|
fd.write(file_content)
|
|
56
58
|
|
|
57
59
|
def list_file(self) -> List[str]:
|
|
@@ -111,11 +113,11 @@ class YamlUpdatePlugin(Plugin):
|
|
|
111
113
|
|
|
112
114
|
def get_yaml(self) -> Dict[str, Any]:
|
|
113
115
|
# cadl file doesn't have to be relative to output folder
|
|
114
|
-
with open(self.options["cadl_file"], "r") as fd:
|
|
116
|
+
with open(self.options["cadl_file"], "r", encoding="utf-8-sig") as fd:
|
|
115
117
|
return yaml.safe_load(fd.read())
|
|
116
118
|
|
|
117
119
|
def write_yaml(self, yaml_string: str) -> None:
|
|
118
|
-
with open(self.options["cadl_file"], "w") as fd:
|
|
120
|
+
with open(self.options["cadl_file"], "w", encoding="utf-8-sig") as fd:
|
|
119
121
|
fd.write(yaml_string)
|
|
120
122
|
|
|
121
123
|
def process(self) -> bool:
|
package/autorest/_utils.py
CHANGED
|
@@ -77,7 +77,13 @@ def parse_args(
|
|
|
77
77
|
return value
|
|
78
78
|
|
|
79
79
|
unknown_args_ret = {
|
|
80
|
-
ua.strip("--").split("=")[
|
|
80
|
+
ua.strip("--").split("=", maxsplit=1)[ # pylint: disable=bad-str-strip-call
|
|
81
|
+
0
|
|
82
|
+
]: _get_value(
|
|
83
|
+
ua.strip("--").split("=", maxsplit=1)[ # pylint: disable=bad-str-strip-call
|
|
84
|
+
1
|
|
85
|
+
]
|
|
86
|
+
)
|
|
81
87
|
for ua in unknown_args
|
|
82
88
|
}
|
|
83
89
|
return args, unknown_args_ret
|
|
@@ -31,7 +31,12 @@ class BlackScriptPlugin(Plugin): # pylint: disable=abstract-method
|
|
|
31
31
|
|
|
32
32
|
def process(self) -> bool:
|
|
33
33
|
# apply format_file on every file in the output folder
|
|
34
|
-
list(
|
|
34
|
+
list(
|
|
35
|
+
map(
|
|
36
|
+
self.format_file,
|
|
37
|
+
[Path(f) for f in self.list_file() if "__pycache__" not in f],
|
|
38
|
+
)
|
|
39
|
+
)
|
|
35
40
|
return True
|
|
36
41
|
|
|
37
42
|
def format_file(self, file: Path) -> None:
|
|
@@ -186,7 +186,7 @@ class CodeGenerator(Plugin):
|
|
|
186
186
|
|
|
187
187
|
def get_yaml(self) -> Dict[str, Any]:
|
|
188
188
|
# cadl file doesn't have to be relative to output folder
|
|
189
|
-
with open(self.options["cadl_file"], "r") as fd:
|
|
189
|
+
with open(self.options["cadl_file"], "r", encoding="utf-8-sig") as fd:
|
|
190
190
|
return yaml.safe_load(fd.read())
|
|
191
191
|
|
|
192
192
|
def get_serializer(self, code_model: CodeModel):
|
|
@@ -52,9 +52,7 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
52
52
|
) -> "BaseType":
|
|
53
53
|
return cls(yaml_data=yaml_data, code_model=code_model)
|
|
54
54
|
|
|
55
|
-
def imports( # pylint: disable=
|
|
56
|
-
self, **kwargs # pylint: disable=unused-argument
|
|
57
|
-
) -> FileImport:
|
|
55
|
+
def imports(self, **kwargs) -> FileImport: # pylint: disable=unused-argument
|
|
58
56
|
return FileImport()
|
|
59
57
|
|
|
60
58
|
def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
|
|
@@ -91,7 +89,7 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
91
89
|
if self.xml_metadata.get("namespace", False):
|
|
92
90
|
attrs_list.append(f"'ns': '{self.xml_metadata['namespace']}'")
|
|
93
91
|
if self.xml_metadata.get("text"):
|
|
94
|
-
attrs_list.append(
|
|
92
|
+
attrs_list.append("'text': True")
|
|
95
93
|
return ", ".join(attrs_list)
|
|
96
94
|
|
|
97
95
|
@property
|
|
@@ -106,7 +104,6 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
106
104
|
If list: '[str]'
|
|
107
105
|
If dict: '{str}'
|
|
108
106
|
"""
|
|
109
|
-
...
|
|
110
107
|
raise NotImplementedError()
|
|
111
108
|
|
|
112
109
|
@property
|
|
@@ -121,12 +118,10 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
121
118
|
@abstractmethod
|
|
122
119
|
def description(self, *, is_operation_file: bool) -> str:
|
|
123
120
|
"""The description"""
|
|
124
|
-
...
|
|
125
121
|
|
|
126
122
|
@abstractmethod
|
|
127
123
|
def docstring_text(self, **kwargs: Any) -> str:
|
|
128
124
|
"""The names used in rtype documentation"""
|
|
129
|
-
...
|
|
130
125
|
|
|
131
126
|
@abstractmethod
|
|
132
127
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
@@ -134,7 +129,6 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
134
129
|
|
|
135
130
|
Special case for enum, for instance: 'str or ~namespace.EnumName'
|
|
136
131
|
"""
|
|
137
|
-
...
|
|
138
132
|
|
|
139
133
|
@abstractmethod
|
|
140
134
|
def type_annotation(self, **kwargs: Any) -> str:
|
|
@@ -142,7 +136,6 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
142
136
|
|
|
143
137
|
Special case for enum, for instance: Union[str, "EnumName"]
|
|
144
138
|
"""
|
|
145
|
-
...
|
|
146
139
|
|
|
147
140
|
@property
|
|
148
141
|
def validation(self) -> Optional[Dict[str, Any]]:
|
|
@@ -153,7 +146,7 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
153
146
|
"""
|
|
154
147
|
return None
|
|
155
148
|
|
|
156
|
-
def get_declaration(self, value: Any) -> str:
|
|
149
|
+
def get_declaration(self, value: Any) -> str:
|
|
157
150
|
"""Return the current value from YAML as a Python string that represents the constant.
|
|
158
151
|
|
|
159
152
|
Example, if schema is "bytearray" and value is "foo",
|
|
@@ -175,9 +168,8 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
175
168
|
description: Optional[str] = None,
|
|
176
169
|
) -> Any:
|
|
177
170
|
"""Template of what this schema would look like as JSON input"""
|
|
178
|
-
...
|
|
179
171
|
|
|
180
|
-
def get_polymorphic_subtypes(
|
|
172
|
+
def get_polymorphic_subtypes(
|
|
181
173
|
self, polymorphic_subtypes: List["ModelType"] # pylint: disable=unused-argument
|
|
182
174
|
) -> None:
|
|
183
175
|
return None
|
|
@@ -186,7 +178,6 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
186
178
|
@abstractmethod
|
|
187
179
|
def instance_check_template(self) -> str:
|
|
188
180
|
"""Template of what an instance check of a variable for this type would look like"""
|
|
189
|
-
...
|
|
190
181
|
|
|
191
182
|
@property
|
|
192
183
|
def serialization_constraints(self) -> List[str]:
|
|
@@ -155,8 +155,10 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
155
155
|
for rb in self.request_builders
|
|
156
156
|
if id(rb.yaml_data) == request_builder_id
|
|
157
157
|
)
|
|
158
|
-
except StopIteration:
|
|
159
|
-
raise KeyError(
|
|
158
|
+
except StopIteration as exc:
|
|
159
|
+
raise KeyError(
|
|
160
|
+
f"No request builder with id {request_builder_id} found."
|
|
161
|
+
) from exc
|
|
160
162
|
|
|
161
163
|
def _imports_shared(self, async_mode: bool) -> FileImport:
|
|
162
164
|
file_import = FileImport()
|
|
@@ -207,20 +209,16 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
207
209
|
def has_lro_operations(self) -> bool:
|
|
208
210
|
"""Are there any LRO operations in this SDK?"""
|
|
209
211
|
return any(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
for operation in operation_group.operations
|
|
214
|
-
]
|
|
212
|
+
operation.operation_type in ("lro", "lropaging")
|
|
213
|
+
for operation_group in self.operation_groups
|
|
214
|
+
for operation in operation_group.operations
|
|
215
215
|
)
|
|
216
216
|
|
|
217
217
|
@property
|
|
218
218
|
def has_operations(self) -> bool:
|
|
219
219
|
return any(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
for operation_group in self.operation_groups
|
|
223
|
-
]
|
|
220
|
+
bool(operation_group.operations)
|
|
221
|
+
for operation_group in self.operation_groups
|
|
224
222
|
)
|
|
225
223
|
|
|
226
224
|
def format_lro_operations(self) -> None:
|
|
@@ -172,8 +172,8 @@ class CodeModel: # pylint: disable=too-many-public-methods
|
|
|
172
172
|
"""
|
|
173
173
|
try:
|
|
174
174
|
return next(type for id, type in self.types_map.items() if id == schema_id)
|
|
175
|
-
except StopIteration:
|
|
176
|
-
raise KeyError(f"Couldn't find schema with id {schema_id}")
|
|
175
|
+
except StopIteration as exc:
|
|
176
|
+
raise KeyError(f"Couldn't find schema with id {schema_id}") from exc
|
|
177
177
|
|
|
178
178
|
@property
|
|
179
179
|
def model_types(self) -> List[ModelType]:
|
|
@@ -38,7 +38,6 @@ class _CredentialPolicyBaseType:
|
|
|
38
38
|
"""
|
|
39
39
|
How to call this credential policy. Used to initialize the credential policy in the config file.
|
|
40
40
|
"""
|
|
41
|
-
...
|
|
42
41
|
|
|
43
42
|
|
|
44
43
|
class BearerTokenCredentialPolicyType(_CredentialPolicyBaseType):
|
|
@@ -158,17 +157,17 @@ class TokenCredentialType(
|
|
|
158
157
|
):
|
|
159
158
|
"""Type of a token credential. Used by BearerAuth and ARMChallenge policies"""
|
|
160
159
|
|
|
161
|
-
def type_annotation(self, **kwargs: Any) -> str:
|
|
160
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
162
161
|
if kwargs.get("async_mode"):
|
|
163
162
|
return '"AsyncTokenCredential"'
|
|
164
163
|
return '"TokenCredential"'
|
|
165
164
|
|
|
166
|
-
def docstring_type(self, **kwargs: Any) -> str:
|
|
165
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
167
166
|
if kwargs.get("async_mode"):
|
|
168
167
|
return "~azure.core.credentials_async.AsyncTokenCredential"
|
|
169
168
|
return "~azure.core.credentials.TokenCredential"
|
|
170
169
|
|
|
171
|
-
def imports(self, **kwargs: Any) -> FileImport:
|
|
170
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
172
171
|
file_import = FileImport()
|
|
173
172
|
if kwargs.get("async_mode"):
|
|
174
173
|
file_import.add_submodule_import(
|
|
@@ -188,7 +187,7 @@ class TokenCredentialType(
|
|
|
188
187
|
|
|
189
188
|
@property
|
|
190
189
|
def instance_check_template(self) -> str:
|
|
191
|
-
return "hasattr({}, get_token)"
|
|
190
|
+
return "hasattr({}, 'get_token')"
|
|
192
191
|
|
|
193
192
|
|
|
194
193
|
class AzureKeyCredentialType(
|
|
@@ -197,23 +196,17 @@ class AzureKeyCredentialType(
|
|
|
197
196
|
):
|
|
198
197
|
"""Type for an AzureKeyCredential"""
|
|
199
198
|
|
|
200
|
-
def docstring_type( # pylint: disable=
|
|
201
|
-
self, **kwargs: Any # pylint: disable=unused-argument
|
|
202
|
-
) -> str:
|
|
199
|
+
def docstring_type(self, **kwargs: Any) -> str: # pylint: disable=unused-argument
|
|
203
200
|
return "~azure.core.credentials.AzureKeyCredential"
|
|
204
201
|
|
|
205
|
-
def type_annotation( # pylint: disable=
|
|
206
|
-
self, **kwargs: Any # pylint: disable=unused-argument
|
|
207
|
-
) -> str:
|
|
202
|
+
def type_annotation(self, **kwargs: Any) -> str: # pylint: disable=unused-argument
|
|
208
203
|
return "AzureKeyCredential"
|
|
209
204
|
|
|
210
205
|
@property
|
|
211
206
|
def instance_check_template(self) -> str:
|
|
212
207
|
return "isinstance({}, AzureKeyCredential)"
|
|
213
208
|
|
|
214
|
-
def imports( # pylint: disable=
|
|
215
|
-
self, **kwargs: Any # pylint: disable=unused-argument
|
|
216
|
-
) -> FileImport:
|
|
209
|
+
def imports(self, **kwargs: Any) -> FileImport: # pylint: disable=unused-argument
|
|
217
210
|
file_import = FileImport()
|
|
218
211
|
file_import.add_submodule_import(
|
|
219
212
|
"azure.core.credentials",
|
|
@@ -73,7 +73,7 @@ class DictionaryType(BaseType):
|
|
|
73
73
|
description: Optional[str] = None,
|
|
74
74
|
) -> Any:
|
|
75
75
|
return {
|
|
76
|
-
|
|
76
|
+
'"str"': self.element_type.get_json_template_representation(
|
|
77
77
|
optional=optional,
|
|
78
78
|
client_default_value_declaration=client_default_value_declaration,
|
|
79
79
|
description=description,
|
|
@@ -228,7 +228,7 @@ class FileImport:
|
|
|
228
228
|
],
|
|
229
229
|
],
|
|
230
230
|
],
|
|
231
|
-
] =
|
|
231
|
+
] = {}
|
|
232
232
|
for i in self.imports:
|
|
233
233
|
name_import: Optional[
|
|
234
234
|
Union[
|
|
@@ -248,8 +248,8 @@ class FileImport:
|
|
|
248
248
|
name_import = (i.submodule_name, i.alias)
|
|
249
249
|
else:
|
|
250
250
|
name_import = i.submodule_name
|
|
251
|
-
retval.setdefault(i.typing_section,
|
|
252
|
-
i.import_type,
|
|
251
|
+
retval.setdefault(i.typing_section, {}).setdefault(
|
|
252
|
+
i.import_type, {}
|
|
253
253
|
).setdefault(i.module_name, set()).add(name_import)
|
|
254
254
|
return retval
|
|
255
255
|
|
|
@@ -73,11 +73,11 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
73
73
|
response = next(
|
|
74
74
|
r for r in responses_with_bodies if 200 in r.status_codes
|
|
75
75
|
)
|
|
76
|
-
except StopIteration:
|
|
76
|
+
except StopIteration as exc:
|
|
77
77
|
raise ValueError(
|
|
78
|
-
|
|
78
|
+
"Your swagger is invalid because you have multiple response schemas for LRO"
|
|
79
79
|
+ f" method {self.name} and none of them have a 200 status code."
|
|
80
|
-
)
|
|
80
|
+
) from exc
|
|
81
81
|
|
|
82
82
|
elif num_response_schemas:
|
|
83
83
|
response = responses_with_bodies[0]
|
|
@@ -134,8 +134,8 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
134
134
|
return file_import
|
|
135
135
|
if async_mode:
|
|
136
136
|
file_import.add_submodule_import(
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
"azure.core.tracing.decorator_async",
|
|
138
|
+
"distributed_trace_async",
|
|
139
139
|
ImportType.AZURECORE,
|
|
140
140
|
)
|
|
141
141
|
file_import.add_submodule_import(
|
|
@@ -247,13 +247,6 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
247
247
|
retval = add_to_pylint_disable(retval, "too-many-locals")
|
|
248
248
|
return retval
|
|
249
249
|
|
|
250
|
-
def imports(self, **kwargs: Any) -> FileImport:
|
|
251
|
-
file_import = FileImport()
|
|
252
|
-
file_import.add_submodule_import(
|
|
253
|
-
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
254
|
-
)
|
|
255
|
-
return file_import
|
|
256
|
-
|
|
257
250
|
|
|
258
251
|
class JSONModelType(ModelType):
|
|
259
252
|
base = "json"
|
|
@@ -276,7 +269,10 @@ class JSONModelType(ModelType):
|
|
|
276
269
|
return "isinstance({}, MutableMapping)"
|
|
277
270
|
|
|
278
271
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
279
|
-
file_import =
|
|
272
|
+
file_import = FileImport()
|
|
273
|
+
file_import.add_submodule_import(
|
|
274
|
+
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
275
|
+
)
|
|
280
276
|
file_import.define_mutable_mapping_type()
|
|
281
277
|
if self.is_xml:
|
|
282
278
|
file_import.add_submodule_import(
|
|
@@ -322,6 +318,13 @@ class MsrestModelType(GeneratedModelType):
|
|
|
322
318
|
def instance_check_template(self) -> str:
|
|
323
319
|
return "isinstance({}, msrest.Model)"
|
|
324
320
|
|
|
321
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
322
|
+
file_import = super().imports(**kwargs)
|
|
323
|
+
file_import.add_submodule_import(
|
|
324
|
+
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
325
|
+
)
|
|
326
|
+
return file_import
|
|
327
|
+
|
|
325
328
|
|
|
326
329
|
class DPGModelType(GeneratedModelType):
|
|
327
330
|
base = "dpg"
|
|
@@ -394,8 +394,8 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
394
394
|
)
|
|
395
395
|
if self.code_model.options["tracing"] and self.want_tracing and not async_mode:
|
|
396
396
|
file_import.add_submodule_import(
|
|
397
|
-
|
|
398
|
-
|
|
397
|
+
"azure.core.tracing.decorator",
|
|
398
|
+
"distributed_trace",
|
|
399
399
|
ImportType.AZURECORE,
|
|
400
400
|
)
|
|
401
401
|
file_import.merge(
|
|
@@ -410,10 +410,10 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
410
410
|
) -> ResponseType:
|
|
411
411
|
try:
|
|
412
412
|
return next(r for r in self.responses if status_code in r.status_codes)
|
|
413
|
-
except StopIteration:
|
|
413
|
+
except StopIteration as exc:
|
|
414
414
|
raise ValueError(
|
|
415
415
|
f"Incorrect status code {status_code}, operation {self.name}"
|
|
416
|
-
)
|
|
416
|
+
) from exc
|
|
417
417
|
|
|
418
418
|
@property
|
|
419
419
|
def success_status_codes(self) -> List[Union[str, int]]:
|
|
@@ -431,7 +431,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
431
431
|
basename == "operations"
|
|
432
432
|
or self.code_model.options["combine_operation_files"]
|
|
433
433
|
):
|
|
434
|
-
return
|
|
434
|
+
return "_operations"
|
|
435
435
|
return f"_{basename}_operations"
|
|
436
436
|
|
|
437
437
|
@property
|
|
@@ -481,8 +481,8 @@ class Operation(OperationBase[Response]):
|
|
|
481
481
|
return file_import
|
|
482
482
|
if async_mode:
|
|
483
483
|
file_import.add_submodule_import(
|
|
484
|
-
|
|
485
|
-
|
|
484
|
+
"azure.core.tracing.decorator_async",
|
|
485
|
+
"distributed_trace_async",
|
|
486
486
|
ImportType.AZURECORE,
|
|
487
487
|
)
|
|
488
488
|
if (
|
|
@@ -499,7 +499,7 @@ class Operation(OperationBase[Response]):
|
|
|
499
499
|
)
|
|
500
500
|
file_import.add_import("json", ImportType.STDLIB)
|
|
501
501
|
if self.default_error_deserialization or any(
|
|
502
|
-
|
|
502
|
+
r.type for r in self.responses
|
|
503
503
|
):
|
|
504
504
|
file_import.add_submodule_import(
|
|
505
505
|
f"{relative_path}_model_base", "_deserialize", ImportType.LOCAL
|
|
@@ -76,7 +76,9 @@ class OperationGroup(BaseModel):
|
|
|
76
76
|
def imports(self, async_mode: bool) -> FileImport:
|
|
77
77
|
file_import = FileImport()
|
|
78
78
|
|
|
79
|
-
relative_path = "..." if async_mode else ".."
|
|
79
|
+
relative_path = ("..." if async_mode else "..") + (
|
|
80
|
+
"." if self.client.is_subclient else ""
|
|
81
|
+
)
|
|
80
82
|
for operation in self.operations:
|
|
81
83
|
file_import.merge(
|
|
82
84
|
operation.imports(async_mode, relative_path=relative_path)
|
|
@@ -74,10 +74,10 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
74
74
|
for p in cast(ModelType, response.type).properties
|
|
75
75
|
if p.rest_api_name == rest_api_name
|
|
76
76
|
)
|
|
77
|
-
except StopIteration:
|
|
77
|
+
except StopIteration as exc:
|
|
78
78
|
raise ValueError(
|
|
79
79
|
f"Can't find a matching property in response for {rest_api_name}"
|
|
80
|
-
)
|
|
80
|
+
) from exc
|
|
81
81
|
|
|
82
82
|
def get_pager(self, async_mode: bool) -> str:
|
|
83
83
|
return self.responses[0].get_pager(async_mode)
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import abc
|
|
7
|
-
from enum import Enum
|
|
7
|
+
from enum import Enum
|
|
8
8
|
|
|
9
9
|
from typing import (
|
|
10
10
|
Dict,
|
|
@@ -22,6 +22,8 @@ from .base import BaseModel
|
|
|
22
22
|
from .base import BaseType
|
|
23
23
|
from .constant_type import ConstantType
|
|
24
24
|
from .utils import add_to_description
|
|
25
|
+
from .combined_type import CombinedType
|
|
26
|
+
from .model_type import JSONModelType
|
|
25
27
|
|
|
26
28
|
if TYPE_CHECKING:
|
|
27
29
|
from .code_model import CodeModel
|
|
@@ -37,10 +39,10 @@ class ParameterLocation(str, Enum):
|
|
|
37
39
|
OTHER = "other"
|
|
38
40
|
|
|
39
41
|
|
|
40
|
-
class ParameterMethodLocation(Enum):
|
|
41
|
-
POSITIONAL =
|
|
42
|
-
KEYWORD_ONLY =
|
|
43
|
-
KWARG =
|
|
42
|
+
class ParameterMethodLocation(str, Enum):
|
|
43
|
+
POSITIONAL = "positional"
|
|
44
|
+
KEYWORD_ONLY = "keywordOnly"
|
|
45
|
+
KWARG = "kwarg"
|
|
44
46
|
|
|
45
47
|
|
|
46
48
|
class ParameterDelimeter(str, Enum):
|
|
@@ -241,6 +243,20 @@ class BodyParameter(_BodyParameterBase):
|
|
|
241
243
|
def default_content_type(self) -> str:
|
|
242
244
|
return self.yaml_data["defaultContentType"]
|
|
243
245
|
|
|
246
|
+
@staticmethod
|
|
247
|
+
def _has_json_model_type(t: BaseType) -> bool:
|
|
248
|
+
if isinstance(t, JSONModelType):
|
|
249
|
+
return True
|
|
250
|
+
if isinstance(t, CombinedType):
|
|
251
|
+
for sub_t in t.types:
|
|
252
|
+
if BodyParameter._has_json_model_type(sub_t):
|
|
253
|
+
return True
|
|
254
|
+
return False
|
|
255
|
+
|
|
256
|
+
@property
|
|
257
|
+
def has_json_model_type(self) -> bool:
|
|
258
|
+
return BodyParameter._has_json_model_type(self.type)
|
|
259
|
+
|
|
244
260
|
@classmethod
|
|
245
261
|
def from_yaml(
|
|
246
262
|
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
@@ -314,6 +330,7 @@ class Parameter(_ParameterBase):
|
|
|
314
330
|
self.in_overload: bool = self.yaml_data["inOverload"]
|
|
315
331
|
self.in_overriden: bool = self.yaml_data.get("inOverriden", False)
|
|
316
332
|
self.delimiter: Optional[ParameterDelimeter] = self.yaml_data.get("delimiter")
|
|
333
|
+
self.in_flattened_body: bool = self.yaml_data.get("inFlattenedBody", False)
|
|
317
334
|
|
|
318
335
|
@property
|
|
319
336
|
def in_method_signature(self) -> bool:
|
|
@@ -334,9 +351,13 @@ class Parameter(_ParameterBase):
|
|
|
334
351
|
return bool(self.rest_api_name) and self.rest_api_name.lower() == "content-type"
|
|
335
352
|
|
|
336
353
|
@property
|
|
337
|
-
def method_location(
|
|
354
|
+
def method_location( # pylint: disable=too-many-return-statements
|
|
355
|
+
self,
|
|
356
|
+
) -> ParameterMethodLocation:
|
|
338
357
|
if not self.in_method_signature:
|
|
339
358
|
raise ValueError(f"Parameter '{self.client_name}' is not in the method.")
|
|
359
|
+
if self.code_model.options["models_mode"] == "dpg" and self.in_flattened_body:
|
|
360
|
+
return ParameterMethodLocation.KEYWORD_ONLY
|
|
340
361
|
if self.grouper:
|
|
341
362
|
return ParameterMethodLocation.POSITIONAL
|
|
342
363
|
if self.constant:
|
|
@@ -115,7 +115,6 @@ class _ParameterListBase(
|
|
|
115
115
|
@abstractmethod
|
|
116
116
|
def parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], ParameterType]:
|
|
117
117
|
"""Callable for creating parameters"""
|
|
118
|
-
...
|
|
119
118
|
|
|
120
119
|
@staticmethod
|
|
121
120
|
@abstractmethod
|
|
@@ -123,7 +122,6 @@ class _ParameterListBase(
|
|
|
123
122
|
[Dict[str, Any], "CodeModel"], BodyParameterType
|
|
124
123
|
]:
|
|
125
124
|
"""Callable for creating body parameters"""
|
|
126
|
-
...
|
|
127
125
|
|
|
128
126
|
@property
|
|
129
127
|
def grouped(self) -> List[Union[ParameterType, BodyParameterType]]:
|
|
@@ -208,7 +206,6 @@ class _ParameterListBase(
|
|
|
208
206
|
@abstractmethod
|
|
209
207
|
def implementation(self) -> str:
|
|
210
208
|
"""Whether this is a client or a method parameter"""
|
|
211
|
-
...
|
|
212
209
|
|
|
213
210
|
@property
|
|
214
211
|
def unsorted_method_params(self) -> List[Union[ParameterType, BodyParameterType]]:
|
|
@@ -339,8 +336,6 @@ class _ParameterList(
|
|
|
339
336
|
class ParameterList(_ParameterList):
|
|
340
337
|
"""ParameterList is the parameter list for Operation classes"""
|
|
341
338
|
|
|
342
|
-
...
|
|
343
|
-
|
|
344
339
|
|
|
345
340
|
class _RequestBuilderParameterList(
|
|
346
341
|
_ParameterListBase[ # pylint: disable=unsubscriptable-object
|
|
@@ -406,8 +401,6 @@ class _RequestBuilderParameterList(
|
|
|
406
401
|
class RequestBuilderParameterList(_RequestBuilderParameterList):
|
|
407
402
|
"""Parameter list for Request Builder"""
|
|
408
403
|
|
|
409
|
-
...
|
|
410
|
-
|
|
411
404
|
|
|
412
405
|
class OverloadedRequestBuilderParameterList(_RequestBuilderParameterList):
|
|
413
406
|
"""Parameter list for OverloadedRequestBuilder"""
|
|
@@ -423,8 +416,7 @@ class OverloadedRequestBuilderParameterList(_RequestBuilderParameterList):
|
|
|
423
416
|
]
|
|
424
417
|
|
|
425
418
|
|
|
426
|
-
class _ClientGlobalParameterList(
|
|
427
|
-
# pylint: disable=unsubscriptable-object
|
|
419
|
+
class _ClientGlobalParameterList( # pylint: disable=abstract-method
|
|
428
420
|
_ParameterListBase[ParameterType, BodyParameter]
|
|
429
421
|
):
|
|
430
422
|
"""Base parameter list for client and config classes"""
|
|
@@ -133,7 +133,7 @@ class BinaryIteratorType(PrimitiveType):
|
|
|
133
133
|
|
|
134
134
|
@property
|
|
135
135
|
def default_template_representation_declaration(self) -> str:
|
|
136
|
-
return self.get_declaration(
|
|
136
|
+
return self.get_declaration("Iterator[bytes]")
|
|
137
137
|
|
|
138
138
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
139
139
|
file_import = FileImport()
|
|
@@ -129,13 +129,25 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
129
129
|
retval.update(self.type.validation or {})
|
|
130
130
|
return retval or None
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
@staticmethod
|
|
133
|
+
def contain_model_type(t: BaseType) -> bool:
|
|
134
|
+
from . import ListType, DictionaryType, ModelType
|
|
135
|
+
|
|
136
|
+
if isinstance(t, ModelType):
|
|
137
|
+
return True
|
|
138
|
+
if isinstance(t, ListType):
|
|
139
|
+
return Property.contain_model_type(t.element_type)
|
|
140
|
+
if isinstance(t, DictionaryType):
|
|
141
|
+
return Property.contain_model_type(t.element_type)
|
|
142
|
+
if isinstance(t, ConstantType):
|
|
143
|
+
return Property.contain_model_type(t.value_type)
|
|
144
|
+
return False
|
|
134
145
|
|
|
146
|
+
def imports(self, **kwargs) -> FileImport:
|
|
135
147
|
file_import = self.type.imports(**kwargs, is_operation_file=False)
|
|
136
148
|
if self.optional and self.client_default_value is None:
|
|
137
149
|
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
|
|
138
|
-
if
|
|
150
|
+
if self.contain_model_type(self.type):
|
|
139
151
|
file_import.add_submodule_import(
|
|
140
152
|
"..",
|
|
141
153
|
"models",
|
|
@@ -49,12 +49,12 @@ class Response(BaseModel):
|
|
|
49
49
|
yaml_data: Dict[str, Any],
|
|
50
50
|
code_model: "CodeModel",
|
|
51
51
|
*,
|
|
52
|
-
headers: List[ResponseHeader] =
|
|
52
|
+
headers: Optional[List[ResponseHeader]] = None,
|
|
53
53
|
type: Optional[BaseType] = None,
|
|
54
54
|
) -> None:
|
|
55
55
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
56
56
|
self.status_codes: List[Union[int, str]] = yaml_data["statusCodes"]
|
|
57
|
-
self.headers = headers
|
|
57
|
+
self.headers = headers or []
|
|
58
58
|
self.type = type
|
|
59
59
|
self.nullable = yaml_data.get("nullable")
|
|
60
60
|
|
|
@@ -462,7 +462,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
462
462
|
if self.code_model.need_vendored_code(async_mode=False):
|
|
463
463
|
self.write_file(
|
|
464
464
|
namespace_path / Path("_vendor.py"),
|
|
465
|
-
general_serializer.serialize_vendor_file(),
|
|
465
|
+
general_serializer.serialize_vendor_file(clients),
|
|
466
466
|
)
|
|
467
467
|
|
|
468
468
|
self._serialize_and_write_version_file(namespace_path, general_serializer)
|
|
@@ -521,7 +521,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
521
521
|
if self.code_model.need_vendored_code(async_mode=True):
|
|
522
522
|
self.write_file(
|
|
523
523
|
aio_path / Path("_vendor.py"),
|
|
524
|
-
aio_general_serializer.serialize_vendor_file(),
|
|
524
|
+
aio_general_serializer.serialize_vendor_file(clients),
|
|
525
525
|
)
|
|
526
526
|
|
|
527
527
|
def _serialize_and_write_metadata(
|