@autorest/python 6.13.11 → 6.13.13
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/_utils.py +5 -3
- package/autorest/codegen/__init__.py +5 -3
- package/autorest/codegen/models/base_builder.py +3 -6
- package/autorest/codegen/models/client.py +1 -3
- package/autorest/codegen/models/enum_type.py +5 -3
- package/autorest/codegen/models/lro_operation.py +2 -2
- package/autorest/codegen/models/model_type.py +13 -9
- package/autorest/codegen/models/paging_operation.py +2 -2
- package/autorest/codegen/models/parameter.py +1 -2
- package/autorest/codegen/models/primitive_types.py +20 -12
- package/autorest/codegen/models/request_builder.py +9 -8
- package/autorest/codegen/serializers/__init__.py +1 -1
- package/autorest/codegen/serializers/builder_serializer.py +45 -36
- package/autorest/codegen/serializers/client_serializer.py +3 -3
- package/autorest/codegen/serializers/metadata_serializer.py +5 -5
- package/autorest/codegen/serializers/model_serializer.py +2 -4
- package/autorest/codegen/templates/model_base.py.jinja2 +56 -50
- package/autorest/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +0 -1
- package/autorest/m4reformatter/__init__.py +5 -3
- package/autorest/preprocess/__init__.py +6 -6
- package/package.json +1 -1
- package/requirements.txt +1 -1
package/autorest/_utils.py
CHANGED
|
@@ -136,9 +136,11 @@ def build_policies(
|
|
|
136
136
|
"self._config.user_agent_policy",
|
|
137
137
|
"self._config.proxy_policy",
|
|
138
138
|
"policies.ContentDecodePolicy(**kwargs)",
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
(
|
|
140
|
+
f"{async_prefix}ARMAutoResourceProviderRegistrationPolicy()"
|
|
141
|
+
if is_arm
|
|
142
|
+
else None
|
|
143
|
+
),
|
|
142
144
|
"self._config.redirect_policy",
|
|
143
145
|
"self._config.retry_policy",
|
|
144
146
|
"self._config.authentication_policy",
|
|
@@ -62,9 +62,11 @@ class OptionsRetriever:
|
|
|
62
62
|
def license_header(self) -> str:
|
|
63
63
|
license_header = self.options.get(
|
|
64
64
|
"header-text",
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
(
|
|
66
|
+
DEFAULT_HEADER_TEXT.format(company_name=self.company_name)
|
|
67
|
+
if self.company_name
|
|
68
|
+
else ""
|
|
69
|
+
),
|
|
68
70
|
)
|
|
69
71
|
if license_header:
|
|
70
72
|
license_header = license_header.replace("\n", "\n# ")
|
|
@@ -100,16 +100,13 @@ class BaseBuilder(
|
|
|
100
100
|
return ""
|
|
101
101
|
|
|
102
102
|
@abstractmethod
|
|
103
|
-
def response_type_annotation(self, **kwargs) -> str:
|
|
104
|
-
...
|
|
103
|
+
def response_type_annotation(self, **kwargs) -> str: ...
|
|
105
104
|
|
|
106
105
|
@abstractmethod
|
|
107
|
-
def response_docstring_text(self, **kwargs) -> str:
|
|
108
|
-
...
|
|
106
|
+
def response_docstring_text(self, **kwargs) -> str: ...
|
|
109
107
|
|
|
110
108
|
@abstractmethod
|
|
111
|
-
def response_docstring_type(self, **kwargs) -> str:
|
|
112
|
-
...
|
|
109
|
+
def response_docstring_type(self, **kwargs) -> str: ...
|
|
113
110
|
|
|
114
111
|
@property
|
|
115
112
|
def description(self) -> str:
|
|
@@ -350,9 +350,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
350
350
|
elif self.code_model.options["models_mode"] == "msrest":
|
|
351
351
|
# in this case, we have client_models = {} in the service client, which needs a type annotation
|
|
352
352
|
# this import will always be commented, so will always add it to the typing section
|
|
353
|
-
file_import.add_submodule_import(
|
|
354
|
-
"typing", "Dict", ImportType.STDLIB, TypingSection.TYPING
|
|
355
|
-
)
|
|
353
|
+
file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB)
|
|
356
354
|
file_import.add_submodule_import("copy", "deepcopy", ImportType.STDLIB)
|
|
357
355
|
return file_import
|
|
358
356
|
|
|
@@ -256,8 +256,10 @@ class EnumType(BaseType):
|
|
|
256
256
|
"models",
|
|
257
257
|
ImportType.LOCAL,
|
|
258
258
|
alias="_models",
|
|
259
|
-
typing_section=
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
typing_section=(
|
|
260
|
+
TypingSection.TYPING
|
|
261
|
+
if kwargs.get("model_typing")
|
|
262
|
+
else TypingSection.REGULAR
|
|
263
|
+
),
|
|
262
264
|
)
|
|
263
265
|
return file_import
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# pylint: disable=multiple-statements
|
|
1
2
|
# -------------------------------------------------------------------------
|
|
2
3
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
4
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
@@ -151,5 +152,4 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
151
152
|
return file_import
|
|
152
153
|
|
|
153
154
|
|
|
154
|
-
class LROOperation(LROOperationBase[LROResponse]):
|
|
155
|
-
...
|
|
155
|
+
class LROOperation(LROOperationBase[LROResponse]): ...
|
|
@@ -165,9 +165,9 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
165
165
|
]
|
|
166
166
|
}
|
|
167
167
|
if self.discriminator and self.discriminator_value:
|
|
168
|
-
representation[
|
|
169
|
-
f'"{self.
|
|
170
|
-
|
|
168
|
+
representation[f'"{self.discriminator.wire_name}"'] = (
|
|
169
|
+
f'"{self.discriminator_value}"'
|
|
170
|
+
)
|
|
171
171
|
|
|
172
172
|
# once we've finished, we want to reset created_json_template_representation to false
|
|
173
173
|
# so we can call it again
|
|
@@ -333,18 +333,22 @@ class GeneratedModelType(ModelType): # pylint: disable=abstract-method
|
|
|
333
333
|
"models",
|
|
334
334
|
ImportType.LOCAL,
|
|
335
335
|
alias="_models",
|
|
336
|
-
typing_section=
|
|
337
|
-
|
|
338
|
-
|
|
336
|
+
typing_section=(
|
|
337
|
+
TypingSection.TYPING
|
|
338
|
+
if kwargs.get("model_typing")
|
|
339
|
+
else TypingSection.REGULAR
|
|
340
|
+
),
|
|
339
341
|
)
|
|
340
342
|
if self.is_form_data:
|
|
341
343
|
file_import.add_submodule_import(
|
|
342
344
|
relative_path,
|
|
343
345
|
"_model_base",
|
|
344
346
|
ImportType.LOCAL,
|
|
345
|
-
typing_section=
|
|
346
|
-
|
|
347
|
-
|
|
347
|
+
typing_section=(
|
|
348
|
+
TypingSection.TYPING
|
|
349
|
+
if kwargs.get("model_typing")
|
|
350
|
+
else TypingSection.REGULAR
|
|
351
|
+
),
|
|
348
352
|
)
|
|
349
353
|
return file_import
|
|
350
354
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# pylint: disable=multiple-statements
|
|
1
2
|
# -------------------------------------------------------------------------
|
|
2
3
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
4
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
@@ -182,5 +183,4 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
182
183
|
return file_import
|
|
183
184
|
|
|
184
185
|
|
|
185
|
-
class PagingOperation(PagingOperationBase[PagingResponse]):
|
|
186
|
-
...
|
|
186
|
+
class PagingOperation(PagingOperationBase[PagingResponse]): ...
|
|
@@ -227,8 +227,7 @@ class _ParameterBase(
|
|
|
227
227
|
|
|
228
228
|
@property
|
|
229
229
|
@abc.abstractmethod
|
|
230
|
-
def in_method_signature(self) -> bool:
|
|
231
|
-
...
|
|
230
|
+
def in_method_signature(self) -> bool: ...
|
|
232
231
|
|
|
233
232
|
def method_signature(self, async_mode: bool) -> str:
|
|
234
233
|
type_annot = self.type_annotation(async_mode=async_mode)
|
|
@@ -228,18 +228,26 @@ class NumberType(PrimitiveType): # pylint: disable=abstract-method
|
|
|
228
228
|
@property
|
|
229
229
|
def serialization_constraints(self) -> List[str]:
|
|
230
230
|
validation_constraints = [
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
231
|
+
(
|
|
232
|
+
f"maximum_ex={self.maximum}"
|
|
233
|
+
if self.maximum is not None and self.exclusive_maximum
|
|
234
|
+
else None
|
|
235
|
+
),
|
|
236
|
+
(
|
|
237
|
+
f"maximum={self.maximum}"
|
|
238
|
+
if self.maximum is not None and not self.exclusive_maximum
|
|
239
|
+
else None
|
|
240
|
+
),
|
|
241
|
+
(
|
|
242
|
+
f"minimum_ex={self.minimum}"
|
|
243
|
+
if self.minimum is not None and self.exclusive_minimum
|
|
244
|
+
else None
|
|
245
|
+
),
|
|
246
|
+
(
|
|
247
|
+
f"minimum={self.minimum}"
|
|
248
|
+
if self.minimum is not None and not self.exclusive_minimum
|
|
249
|
+
else None
|
|
250
|
+
),
|
|
243
251
|
f"multiple={self.multiple}" if self.multiple else None,
|
|
244
252
|
]
|
|
245
253
|
return [x for x in validation_constraints if x is not None]
|
|
@@ -117,12 +117,14 @@ class RequestBuilderBase(BaseBuilder[ParameterListType, List["RequestBuilder"]])
|
|
|
117
117
|
"typing", "Any", ImportType.STDLIB, typing_section=TypingSection.CONDITIONAL
|
|
118
118
|
)
|
|
119
119
|
file_import.add_msrest_import(
|
|
120
|
-
relative_path=
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
relative_path=(
|
|
121
|
+
"..."
|
|
122
|
+
if (
|
|
123
|
+
not self.code_model.options["builders_visibility"] == "embedded"
|
|
124
|
+
and self.group_name
|
|
125
|
+
)
|
|
126
|
+
else ".."
|
|
127
|
+
),
|
|
126
128
|
msrest_import_type=MsrestImportType.Serializer,
|
|
127
129
|
typing_section=TypingSection.REGULAR,
|
|
128
130
|
)
|
|
@@ -137,8 +139,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType, List["RequestBuilder"]])
|
|
|
137
139
|
@abstractmethod
|
|
138
140
|
def parameter_list_type() -> (
|
|
139
141
|
Callable[[Dict[str, Any], "CodeModel"], ParameterListType]
|
|
140
|
-
):
|
|
141
|
-
...
|
|
142
|
+
): ...
|
|
142
143
|
|
|
143
144
|
@classmethod
|
|
144
145
|
def get_name(
|
|
@@ -524,7 +524,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
524
524
|
)
|
|
525
525
|
if self.code_model.options.get("emit_cross_language_definition_file"):
|
|
526
526
|
self.write_file(
|
|
527
|
-
|
|
527
|
+
Path("./apiview_mapping_python.json"),
|
|
528
528
|
general_serializer.serialize_cross_language_definition_file(),
|
|
529
529
|
)
|
|
530
530
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# pylint: disable=too-many-lines
|
|
1
|
+
# pylint: disable=too-many-lines,multiple-statements
|
|
2
2
|
# -------------------------------------------------------------------------
|
|
3
3
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
@@ -262,8 +262,7 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
262
262
|
|
|
263
263
|
@property
|
|
264
264
|
@abstractmethod
|
|
265
|
-
def _need_self_param(self) -> bool:
|
|
266
|
-
...
|
|
265
|
+
def _need_self_param(self) -> bool: ...
|
|
267
266
|
|
|
268
267
|
@property
|
|
269
268
|
@abstractmethod
|
|
@@ -378,8 +377,7 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
378
377
|
|
|
379
378
|
@property
|
|
380
379
|
@abstractmethod
|
|
381
|
-
def _json_response_template_name(self) -> str:
|
|
382
|
-
...
|
|
380
|
+
def _json_response_template_name(self) -> str: ...
|
|
383
381
|
|
|
384
382
|
def _json_input_example_template(self, builder: BuilderType) -> List[str]:
|
|
385
383
|
template: List[str] = []
|
|
@@ -525,12 +523,16 @@ class RequestBuilderSerializer(
|
|
|
525
523
|
return self.parameter_serializer.pop_kwargs_from_signature(
|
|
526
524
|
builder.parameters.kwargs_to_pop,
|
|
527
525
|
check_kwarg_dict=True,
|
|
528
|
-
pop_headers_kwarg=
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
526
|
+
pop_headers_kwarg=(
|
|
527
|
+
PopKwargType.CASE_INSENSITIVE
|
|
528
|
+
if bool(builder.parameters.headers)
|
|
529
|
+
else PopKwargType.NO
|
|
530
|
+
),
|
|
531
|
+
pop_params_kwarg=(
|
|
532
|
+
PopKwargType.CASE_INSENSITIVE
|
|
533
|
+
if bool(builder.parameters.query)
|
|
534
|
+
else PopKwargType.NO
|
|
535
|
+
),
|
|
534
536
|
)
|
|
535
537
|
|
|
536
538
|
@staticmethod
|
|
@@ -711,16 +713,20 @@ class _OperationSerializer(
|
|
|
711
713
|
kwargs = self.parameter_serializer.pop_kwargs_from_signature(
|
|
712
714
|
kwargs_to_pop,
|
|
713
715
|
check_kwarg_dict=True,
|
|
714
|
-
pop_headers_kwarg=
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
716
|
+
pop_headers_kwarg=(
|
|
717
|
+
PopKwargType.CASE_INSENSITIVE
|
|
718
|
+
if builder.has_kwargs_to_pop_with_default(
|
|
719
|
+
kwargs_to_pop, ParameterLocation.HEADER # type: ignore
|
|
720
|
+
)
|
|
721
|
+
else PopKwargType.SIMPLE
|
|
722
|
+
),
|
|
723
|
+
pop_params_kwarg=(
|
|
724
|
+
PopKwargType.CASE_INSENSITIVE
|
|
725
|
+
if builder.has_kwargs_to_pop_with_default(
|
|
726
|
+
kwargs_to_pop, ParameterLocation.QUERY # type: ignore
|
|
727
|
+
)
|
|
728
|
+
else PopKwargType.SIMPLE
|
|
729
|
+
),
|
|
724
730
|
check_client_input=not self.code_model.options["multiapi"],
|
|
725
731
|
operation_name=f"('{builder.name}')" if builder.group_name == "" else "",
|
|
726
732
|
)
|
|
@@ -1217,9 +1223,11 @@ class _OperationSerializer(
|
|
|
1217
1223
|
retval.append(
|
|
1218
1224
|
" raise HttpResponseError(response=response{}{})".format(
|
|
1219
1225
|
error_model,
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1226
|
+
(
|
|
1227
|
+
", error_format=ARMErrorFormat"
|
|
1228
|
+
if self.code_model.options["azure_arm"]
|
|
1229
|
+
else ""
|
|
1230
|
+
),
|
|
1223
1231
|
)
|
|
1224
1232
|
)
|
|
1225
1233
|
return retval
|
|
@@ -1364,8 +1372,7 @@ class _OperationSerializer(
|
|
|
1364
1372
|
return "await " if self.async_mode else ""
|
|
1365
1373
|
|
|
1366
1374
|
|
|
1367
|
-
class OperationSerializer(_OperationSerializer[Operation]):
|
|
1368
|
-
...
|
|
1375
|
+
class OperationSerializer(_OperationSerializer[Operation]): ...
|
|
1369
1376
|
|
|
1370
1377
|
|
|
1371
1378
|
############################## PAGING OPERATIONS ##############################
|
|
@@ -1552,8 +1559,7 @@ class _PagingOperationSerializer(
|
|
|
1552
1559
|
return retval
|
|
1553
1560
|
|
|
1554
1561
|
|
|
1555
|
-
class PagingOperationSerializer(_PagingOperationSerializer[PagingOperation]):
|
|
1556
|
-
...
|
|
1562
|
+
class PagingOperationSerializer(_PagingOperationSerializer[PagingOperation]): ...
|
|
1557
1563
|
|
|
1558
1564
|
|
|
1559
1565
|
############################## LRO OPERATIONS ##############################
|
|
@@ -1682,12 +1688,16 @@ class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
|
|
|
1682
1688
|
retval.append(" if cls:")
|
|
1683
1689
|
retval.append(
|
|
1684
1690
|
" return cls(pipeline_response, {}, {}){}".format(
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
+
(
|
|
1692
|
+
"deserialized"
|
|
1693
|
+
if builder.lro_response and builder.lro_response.type
|
|
1694
|
+
else "None"
|
|
1695
|
+
),
|
|
1696
|
+
(
|
|
1697
|
+
"response_headers"
|
|
1698
|
+
if builder.lro_response and builder.lro_response.headers
|
|
1699
|
+
else "{}"
|
|
1700
|
+
),
|
|
1691
1701
|
" # type: ignore",
|
|
1692
1702
|
)
|
|
1693
1703
|
)
|
|
@@ -1696,8 +1706,7 @@ class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
|
|
|
1696
1706
|
return retval
|
|
1697
1707
|
|
|
1698
1708
|
|
|
1699
|
-
class LROOperationSerializer(_LROOperationSerializer[LROOperation]):
|
|
1700
|
-
...
|
|
1709
|
+
class LROOperationSerializer(_LROOperationSerializer[LROOperation]): ...
|
|
1701
1710
|
|
|
1702
1711
|
|
|
1703
1712
|
############################## LRO PAGING OPERATIONS ##############################
|
|
@@ -206,9 +206,9 @@ class ClientSerializer:
|
|
|
206
206
|
send_request_signature = self._send_request_signature()
|
|
207
207
|
return utils.method_signature_and_response_type_annotation_template(
|
|
208
208
|
method_signature=send_request_signature,
|
|
209
|
-
response_type_annotation=
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
response_type_annotation=(
|
|
210
|
+
"Awaitable[AsyncHttpResponse]" if async_mode else "HttpResponse"
|
|
211
|
+
),
|
|
212
212
|
)
|
|
213
213
|
|
|
214
214
|
def _example_make_call(self, async_mode: bool) -> List[str]:
|
|
@@ -66,11 +66,11 @@ def _json_serialize_imports(
|
|
|
66
66
|
if name_imports:
|
|
67
67
|
name_import_ordered_list = list(name_imports)
|
|
68
68
|
name_import_ordered_list.sort(
|
|
69
|
-
key=lambda e:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
key=lambda e: (
|
|
70
|
+
_to_string(e) # type: ignore
|
|
71
|
+
if isinstance(e, (list, tuple))
|
|
72
|
+
else e if isinstance(e, str) else ""
|
|
73
|
+
)
|
|
74
74
|
)
|
|
75
75
|
json_package_name_dictionary[package_name] = name_import_ordered_list
|
|
76
76
|
json_import_type_dictionary[import_type_key] = json_package_name_dictionary
|
|
@@ -30,8 +30,7 @@ def _documentation_string(
|
|
|
30
30
|
|
|
31
31
|
class _ModelSerializer(BaseSerializer, ABC):
|
|
32
32
|
@abstractmethod
|
|
33
|
-
def imports(self) -> FileImport:
|
|
34
|
-
...
|
|
33
|
+
def imports(self) -> FileImport: ...
|
|
35
34
|
|
|
36
35
|
def serialize(self) -> str:
|
|
37
36
|
# Generate the models
|
|
@@ -44,8 +43,7 @@ class _ModelSerializer(BaseSerializer, ABC):
|
|
|
44
43
|
)
|
|
45
44
|
|
|
46
45
|
@abstractmethod
|
|
47
|
-
def declare_model(self, model: ModelType) -> str:
|
|
48
|
-
...
|
|
46
|
+
def declare_model(self, model: ModelType) -> str: ...
|
|
49
47
|
|
|
50
48
|
@staticmethod
|
|
51
49
|
def escape_dot(s: str):
|
|
@@ -13,7 +13,6 @@ import sys
|
|
|
13
13
|
import logging
|
|
14
14
|
import base64
|
|
15
15
|
import re
|
|
16
|
-
import copy
|
|
17
16
|
import typing
|
|
18
17
|
import enum
|
|
19
18
|
import email.utils
|
|
@@ -347,7 +346,7 @@ _UNSET = object()
|
|
|
347
346
|
|
|
348
347
|
class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=unsubscriptable-object
|
|
349
348
|
def __init__(self, data: typing.Dict[str, typing.Any]) -> None:
|
|
350
|
-
self._data =
|
|
349
|
+
self._data = data
|
|
351
350
|
|
|
352
351
|
def __contains__(self, key: typing.Any) -> bool:
|
|
353
352
|
return key in self._data
|
|
@@ -605,6 +604,56 @@ class Model(_MyMutableMapping):
|
|
|
605
604
|
}
|
|
606
605
|
return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v
|
|
607
606
|
|
|
607
|
+
def _deserialize_model(model_deserializer: typing.Optional[typing.Callable], obj):
|
|
608
|
+
if _is_model(obj):
|
|
609
|
+
return obj
|
|
610
|
+
return _deserialize(model_deserializer, obj)
|
|
611
|
+
|
|
612
|
+
def _deserialize_with_optional(if_obj_deserializer: typing.Optional[typing.Callable], obj):
|
|
613
|
+
if obj is None:
|
|
614
|
+
return obj
|
|
615
|
+
return _deserialize_with_callable(if_obj_deserializer, obj)
|
|
616
|
+
|
|
617
|
+
def _deserialize_with_union(deserializers, obj):
|
|
618
|
+
for deserializer in deserializers:
|
|
619
|
+
try:
|
|
620
|
+
return _deserialize(deserializer, obj)
|
|
621
|
+
except DeserializationError:
|
|
622
|
+
pass
|
|
623
|
+
raise DeserializationError()
|
|
624
|
+
|
|
625
|
+
def _deserialize_dict(
|
|
626
|
+
value_deserializer: typing.Optional[typing.Callable],
|
|
627
|
+
module: typing.Optional[str],
|
|
628
|
+
obj: typing.Dict[typing.Any, typing.Any],
|
|
629
|
+
):
|
|
630
|
+
if obj is None:
|
|
631
|
+
return obj
|
|
632
|
+
return {
|
|
633
|
+
k: _deserialize(value_deserializer, v, module)
|
|
634
|
+
for k, v in obj.items()
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
def _deserialize_multiple_sequence(
|
|
638
|
+
entry_deserializers: typing.List[typing.Optional[typing.Callable]],
|
|
639
|
+
module: typing.Optional[str],
|
|
640
|
+
obj,
|
|
641
|
+
):
|
|
642
|
+
if obj is None:
|
|
643
|
+
return obj
|
|
644
|
+
return type(obj)(
|
|
645
|
+
_deserialize(deserializer, entry, module)
|
|
646
|
+
for entry, deserializer in zip(obj, entry_deserializers)
|
|
647
|
+
)
|
|
648
|
+
|
|
649
|
+
def _deserialize_sequence(
|
|
650
|
+
deserializer: typing.Optional[typing.Callable],
|
|
651
|
+
module: typing.Optional[str],
|
|
652
|
+
obj,
|
|
653
|
+
):
|
|
654
|
+
if obj is None:
|
|
655
|
+
return obj
|
|
656
|
+
return type(obj)(_deserialize(deserializer, entry, module) for entry in obj)
|
|
608
657
|
|
|
609
658
|
def _get_deserialize_callable_from_annotation( # pylint: disable=R0911, R0915, R0912
|
|
610
659
|
annotation: typing.Any,
|
|
@@ -633,11 +682,6 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=R0911, R0915,
|
|
|
633
682
|
if rf:
|
|
634
683
|
rf._is_model = True
|
|
635
684
|
|
|
636
|
-
def _deserialize_model(model_deserializer: typing.Optional[typing.Callable], obj):
|
|
637
|
-
if _is_model(obj):
|
|
638
|
-
return obj
|
|
639
|
-
return _deserialize(model_deserializer, obj)
|
|
640
|
-
|
|
641
685
|
return functools.partial(_deserialize_model, annotation) # pyright: ignore
|
|
642
686
|
except Exception:
|
|
643
687
|
pass
|
|
@@ -656,11 +700,6 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=R0911, R0915,
|
|
|
656
700
|
next(a for a in annotation.__args__ if a != type(None)), module, rf # pyright: ignore
|
|
657
701
|
)
|
|
658
702
|
|
|
659
|
-
def _deserialize_with_optional(if_obj_deserializer: typing.Optional[typing.Callable], obj):
|
|
660
|
-
if obj is None:
|
|
661
|
-
return obj
|
|
662
|
-
return _deserialize_with_callable(if_obj_deserializer, obj)
|
|
663
|
-
|
|
664
703
|
return functools.partial(_deserialize_with_optional, if_obj_deserializer)
|
|
665
704
|
except AttributeError:
|
|
666
705
|
pass
|
|
@@ -674,14 +713,6 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=R0911, R0915,
|
|
|
674
713
|
)
|
|
675
714
|
]
|
|
676
715
|
|
|
677
|
-
def _deserialize_with_union(deserializers, obj):
|
|
678
|
-
for deserializer in deserializers:
|
|
679
|
-
try:
|
|
680
|
-
return _deserialize(deserializer, obj)
|
|
681
|
-
except DeserializationError:
|
|
682
|
-
pass
|
|
683
|
-
raise DeserializationError()
|
|
684
|
-
|
|
685
716
|
return functools.partial(_deserialize_with_union, deserializers)
|
|
686
717
|
|
|
687
718
|
try:
|
|
@@ -690,20 +721,11 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=R0911, R0915,
|
|
|
690
721
|
annotation.__args__[1], module, rf # pyright: ignore
|
|
691
722
|
)
|
|
692
723
|
|
|
693
|
-
|
|
694
|
-
value_deserializer: typing.Optional[typing.Callable],
|
|
695
|
-
obj: typing.Dict[typing.Any, typing.Any],
|
|
696
|
-
):
|
|
697
|
-
if obj is None:
|
|
698
|
-
return obj
|
|
699
|
-
return {
|
|
700
|
-
k: _deserialize(value_deserializer, v, module)
|
|
701
|
-
for k, v in obj.items()
|
|
702
|
-
}
|
|
703
|
-
|
|
724
|
+
|
|
704
725
|
return functools.partial(
|
|
705
726
|
_deserialize_dict,
|
|
706
727
|
value_deserializer,
|
|
728
|
+
module,
|
|
707
729
|
)
|
|
708
730
|
except (AttributeError, IndexError):
|
|
709
731
|
pass
|
|
@@ -711,34 +733,18 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=R0911, R0915,
|
|
|
711
733
|
if annotation._name in ["List", "Set", "Tuple", "Sequence"]: # pyright: ignore
|
|
712
734
|
if len(annotation.__args__) > 1: # pyright: ignore
|
|
713
735
|
|
|
714
|
-
def _deserialize_multiple_sequence(
|
|
715
|
-
entry_deserializers: typing.List[typing.Optional[typing.Callable]],
|
|
716
|
-
obj,
|
|
717
|
-
):
|
|
718
|
-
if obj is None:
|
|
719
|
-
return obj
|
|
720
|
-
return type(obj)(
|
|
721
|
-
_deserialize(deserializer, entry, module)
|
|
722
|
-
for entry, deserializer in zip(obj, entry_deserializers)
|
|
723
|
-
)
|
|
724
736
|
|
|
725
737
|
entry_deserializers = [
|
|
726
738
|
_get_deserialize_callable_from_annotation(dt, module, rf) for dt in annotation.__args__ # pyright: ignore
|
|
727
739
|
]
|
|
728
|
-
return functools.partial(_deserialize_multiple_sequence, entry_deserializers)
|
|
740
|
+
return functools.partial(_deserialize_multiple_sequence, entry_deserializers, module)
|
|
729
741
|
deserializer = _get_deserialize_callable_from_annotation(
|
|
730
742
|
annotation.__args__[0], module, rf # pyright: ignore
|
|
731
743
|
)
|
|
732
744
|
|
|
733
|
-
|
|
734
|
-
deserializer: typing.Optional[typing.Callable],
|
|
735
|
-
obj,
|
|
736
|
-
):
|
|
737
|
-
if obj is None:
|
|
738
|
-
return obj
|
|
739
|
-
return type(obj)(_deserialize(deserializer, entry, module) for entry in obj)
|
|
745
|
+
|
|
740
746
|
|
|
741
|
-
return functools.partial(_deserialize_sequence, deserializer)
|
|
747
|
+
return functools.partial(_deserialize_sequence, deserializer, module)
|
|
742
748
|
except (TypeError, IndexError, AttributeError, SyntaxError):
|
|
743
749
|
pass
|
|
744
750
|
|
|
@@ -1143,9 +1143,11 @@ class M4Reformatter(
|
|
|
1143
1143
|
"name": yaml_data["language"]["default"]["name"],
|
|
1144
1144
|
"description": yaml_data["info"].get("description"),
|
|
1145
1145
|
"parameters": parameters,
|
|
1146
|
-
"url":
|
|
1147
|
-
|
|
1148
|
-
|
|
1146
|
+
"url": (
|
|
1147
|
+
update_client_url(yaml_data)
|
|
1148
|
+
if yaml_data.get("globalParameters")
|
|
1149
|
+
else ""
|
|
1150
|
+
),
|
|
1149
1151
|
}
|
|
1150
1152
|
|
|
1151
1153
|
def update_yaml(self, yaml_data: Dict[str, Any]) -> None:
|
|
@@ -69,9 +69,9 @@ def add_overload(
|
|
|
69
69
|
content_type_param["inOverload"] = True
|
|
70
70
|
content_type_param["inDocstring"] = True
|
|
71
71
|
body_type_description = get_body_type_for_description(overload["bodyParameter"])
|
|
72
|
-
content_type_param[
|
|
73
|
-
"
|
|
74
|
-
|
|
72
|
+
content_type_param["description"] = (
|
|
73
|
+
f"Body Parameter content-type. Content type parameter for {body_type_description} body."
|
|
74
|
+
)
|
|
75
75
|
content_types = yaml_data["bodyParameter"]["contentTypes"]
|
|
76
76
|
if body_type["type"] == "binary" and len(content_types) > 1:
|
|
77
77
|
content_types = "'" + "', '".join(content_types) + "'"
|
|
@@ -110,9 +110,9 @@ def add_overloads_for_body_param(yaml_data: Dict[str, Any]) -> None:
|
|
|
110
110
|
content_type_param["inOverload"] = False
|
|
111
111
|
content_type_param["inOverriden"] = True
|
|
112
112
|
content_type_param["inDocstring"] = True
|
|
113
|
-
content_type_param[
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
content_type_param["clientDefaultValue"] = (
|
|
114
|
+
None # make it none bc it will be overriden, we depend on default of overloads
|
|
115
|
+
)
|
|
116
116
|
content_type_param["optional"] = True
|
|
117
117
|
|
|
118
118
|
|
package/package.json
CHANGED
package/requirements.txt
CHANGED