@autorest/python 6.38.1 → 6.39.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.
- package/README.md +2 -27
- package/autorest/codegen.py +0 -1
- package/autorest/jsonrpc/server.py +0 -3
- package/generator/build/lib/pygen/__init__.py +14 -23
- package/generator/build/lib/pygen/codegen/__init__.py +4 -4
- package/generator/build/lib/pygen/codegen/models/__init__.py +2 -2
- package/generator/build/lib/pygen/codegen/models/base.py +9 -12
- package/generator/build/lib/pygen/codegen/models/base_builder.py +4 -6
- package/generator/build/lib/pygen/codegen/models/client.py +61 -102
- package/generator/build/lib/pygen/codegen/models/code_model.py +29 -29
- package/generator/build/lib/pygen/codegen/models/combined_type.py +7 -7
- package/generator/build/lib/pygen/codegen/models/constant_type.py +4 -11
- package/generator/build/lib/pygen/codegen/models/credential_types.py +9 -11
- package/generator/build/lib/pygen/codegen/models/dictionary_type.py +7 -8
- package/generator/build/lib/pygen/codegen/models/enum_type.py +7 -7
- package/generator/build/lib/pygen/codegen/models/imports.py +24 -29
- package/generator/build/lib/pygen/codegen/models/list_type.py +15 -14
- package/generator/build/lib/pygen/codegen/models/lro_operation.py +6 -6
- package/generator/build/lib/pygen/codegen/models/lro_paging_operation.py +2 -2
- package/generator/build/lib/pygen/codegen/models/model_type.py +11 -11
- package/generator/build/lib/pygen/codegen/models/operation.py +26 -56
- package/generator/build/lib/pygen/codegen/models/operation_group.py +11 -22
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +15 -19
- package/generator/build/lib/pygen/codegen/models/parameter.py +12 -21
- package/generator/build/lib/pygen/codegen/models/parameter_list.py +37 -39
- package/generator/build/lib/pygen/codegen/models/primitive_types.py +24 -18
- package/generator/build/lib/pygen/codegen/models/property.py +10 -10
- package/generator/build/lib/pygen/codegen/models/request_builder.py +7 -8
- package/generator/build/lib/pygen/codegen/models/request_builder_parameter.py +3 -3
- package/generator/build/lib/pygen/codegen/models/response.py +15 -40
- package/generator/build/lib/pygen/codegen/models/utils.py +2 -2
- package/generator/build/lib/pygen/codegen/serializers/__init__.py +26 -42
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +103 -100
- package/generator/build/lib/pygen/codegen/serializers/client_serializer.py +22 -25
- package/generator/build/lib/pygen/codegen/serializers/enum_serializer.py +2 -2
- package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +49 -61
- package/generator/build/lib/pygen/codegen/serializers/import_serializer.py +6 -7
- package/generator/build/lib/pygen/codegen/serializers/model_init_serializer.py +1 -2
- package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +15 -17
- package/generator/build/lib/pygen/codegen/serializers/operation_groups_serializer.py +3 -3
- package/generator/build/lib/pygen/codegen/serializers/operations_init_serializer.py +5 -6
- package/generator/build/lib/pygen/codegen/serializers/parameter_serializer.py +28 -18
- package/generator/build/lib/pygen/codegen/serializers/patch_serializer.py +1 -2
- package/generator/build/lib/pygen/codegen/serializers/request_builders_serializer.py +1 -2
- package/generator/build/lib/pygen/codegen/serializers/sample_serializer.py +9 -14
- package/generator/build/lib/pygen/codegen/serializers/test_serializer.py +7 -7
- package/generator/build/lib/pygen/codegen/serializers/utils.py +2 -2
- package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +30 -24
- package/generator/build/lib/pygen/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/operation_group.py.jinja2 +1 -11
- package/generator/build/lib/pygen/codegen/templates/operations_folder_init.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/CHANGELOG.md.jinja2 +2 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 +13 -2
- package/generator/build/lib/pygen/codegen/templates/patch.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +11 -13
- package/generator/build/lib/pygen/codegen/templates/utils.py.jinja2 +6 -6
- package/generator/build/lib/pygen/preprocess/__init__.py +47 -30
- package/generator/build/lib/pygen/preprocess/helpers.py +2 -2
- package/generator/build/lib/pygen/utils.py +6 -6
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/__init__.py +14 -23
- package/generator/pygen/codegen/__init__.py +4 -4
- package/generator/pygen/codegen/models/__init__.py +2 -2
- package/generator/pygen/codegen/models/base.py +9 -12
- package/generator/pygen/codegen/models/base_builder.py +4 -6
- package/generator/pygen/codegen/models/client.py +61 -102
- package/generator/pygen/codegen/models/code_model.py +29 -29
- package/generator/pygen/codegen/models/combined_type.py +7 -7
- package/generator/pygen/codegen/models/constant_type.py +4 -11
- package/generator/pygen/codegen/models/credential_types.py +9 -11
- package/generator/pygen/codegen/models/dictionary_type.py +7 -8
- package/generator/pygen/codegen/models/enum_type.py +7 -7
- package/generator/pygen/codegen/models/imports.py +24 -29
- package/generator/pygen/codegen/models/list_type.py +15 -14
- package/generator/pygen/codegen/models/lro_operation.py +6 -6
- package/generator/pygen/codegen/models/lro_paging_operation.py +2 -2
- package/generator/pygen/codegen/models/model_type.py +11 -11
- package/generator/pygen/codegen/models/operation.py +26 -56
- package/generator/pygen/codegen/models/operation_group.py +11 -22
- package/generator/pygen/codegen/models/paging_operation.py +15 -19
- package/generator/pygen/codegen/models/parameter.py +12 -21
- package/generator/pygen/codegen/models/parameter_list.py +37 -39
- package/generator/pygen/codegen/models/primitive_types.py +24 -18
- package/generator/pygen/codegen/models/property.py +10 -10
- package/generator/pygen/codegen/models/request_builder.py +7 -8
- package/generator/pygen/codegen/models/request_builder_parameter.py +3 -3
- package/generator/pygen/codegen/models/response.py +15 -40
- package/generator/pygen/codegen/models/utils.py +2 -2
- package/generator/pygen/codegen/serializers/__init__.py +26 -42
- package/generator/pygen/codegen/serializers/builder_serializer.py +103 -100
- package/generator/pygen/codegen/serializers/client_serializer.py +22 -25
- package/generator/pygen/codegen/serializers/enum_serializer.py +2 -2
- package/generator/pygen/codegen/serializers/general_serializer.py +49 -61
- package/generator/pygen/codegen/serializers/import_serializer.py +6 -7
- package/generator/pygen/codegen/serializers/model_init_serializer.py +1 -2
- package/generator/pygen/codegen/serializers/model_serializer.py +15 -17
- package/generator/pygen/codegen/serializers/operation_groups_serializer.py +3 -3
- package/generator/pygen/codegen/serializers/operations_init_serializer.py +5 -6
- package/generator/pygen/codegen/serializers/parameter_serializer.py +28 -18
- package/generator/pygen/codegen/serializers/patch_serializer.py +1 -2
- package/generator/pygen/codegen/serializers/request_builders_serializer.py +1 -2
- package/generator/pygen/codegen/serializers/sample_serializer.py +9 -14
- package/generator/pygen/codegen/serializers/test_serializer.py +7 -7
- package/generator/pygen/codegen/serializers/utils.py +2 -2
- package/generator/pygen/codegen/templates/model_base.py.jinja2 +30 -24
- package/generator/pygen/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/operation_group.py.jinja2 +1 -11
- package/generator/pygen/codegen/templates/operations_folder_init.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/packaging_templates/CHANGELOG.md.jinja2 +2 -1
- package/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +1 -1
- package/generator/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 +13 -2
- package/generator/pygen/codegen/templates/patch.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/serialization.py.jinja2 +11 -13
- package/generator/pygen/codegen/templates/utils.py.jinja2 +6 -6
- package/generator/pygen/preprocess/__init__.py +47 -30
- package/generator/pygen/preprocess/helpers.py +2 -2
- package/generator/pygen/utils.py +6 -6
- package/generator/pygen.egg-info/SOURCES.txt +0 -2
- package/package.json +2 -2
- package/scripts/__pycache__/venvtools.cpython-310.pyc +0 -0
- package/autorest/multiapi/__init__.py +0 -185
- package/autorest/multiapi/models/__init__.py +0 -16
- package/autorest/multiapi/models/client.py +0 -68
- package/autorest/multiapi/models/code_model.py +0 -142
- package/autorest/multiapi/models/config.py +0 -24
- package/autorest/multiapi/models/constant_global_parameter.py +0 -11
- package/autorest/multiapi/models/global_parameter.py +0 -34
- package/autorest/multiapi/models/global_parameters.py +0 -53
- package/autorest/multiapi/models/imports.py +0 -181
- package/autorest/multiapi/models/mixin_operation.py +0 -38
- package/autorest/multiapi/models/operation_group.py +0 -29
- package/autorest/multiapi/models/operation_mixin_group.py +0 -89
- package/autorest/multiapi/serializers/__init__.py +0 -145
- package/autorest/multiapi/serializers/import_serializer.py +0 -181
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +0 -89
- package/autorest/multiapi/templates/multiapi_init.py.jinja2 +0 -22
- package/autorest/multiapi/templates/multiapi_models.py.jinja2 +0 -9
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +0 -39
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +0 -163
- package/autorest/multiapi/templates/multiapi_version.py.jinja2 +0 -8
- package/autorest/multiapi/utils.py +0 -51
- package/generator/build/lib/pygen/codegen/serializers/metadata_serializer.py +0 -216
- package/generator/build/lib/pygen/codegen/templates/metadata.json.jinja2 +0 -167
- package/generator/pygen/codegen/serializers/metadata_serializer.py +0 -216
- package/generator/pygen/codegen/templates/metadata.json.jinja2 +0 -167
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import datetime
|
|
7
7
|
import decimal
|
|
8
|
-
from typing import Any,
|
|
8
|
+
from typing import Any, Optional, Union, TYPE_CHECKING
|
|
9
9
|
|
|
10
10
|
from .base import BaseType
|
|
11
11
|
from .imports import FileImport, ImportType, TypingSection
|
|
@@ -61,7 +61,7 @@ class BooleanType(PrimitiveType):
|
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
class BinaryType(PrimitiveType):
|
|
64
|
-
def __init__(self, yaml_data:
|
|
64
|
+
def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
|
|
65
65
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
66
66
|
self.type = "IO"
|
|
67
67
|
|
|
@@ -176,7 +176,7 @@ class AnyObjectType(PrimitiveType):
|
|
|
176
176
|
|
|
177
177
|
|
|
178
178
|
class NumberType(PrimitiveType):
|
|
179
|
-
def __init__(self, yaml_data:
|
|
179
|
+
def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
|
|
180
180
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
181
181
|
self.precision: Optional[int] = yaml_data.get("precision")
|
|
182
182
|
self.multiple: Optional[int] = yaml_data.get("multipleOf")
|
|
@@ -186,7 +186,7 @@ class NumberType(PrimitiveType):
|
|
|
186
186
|
self.exclusive_minimum: Optional[int] = yaml_data.get("exclusiveMinimum")
|
|
187
187
|
|
|
188
188
|
@property
|
|
189
|
-
def serialization_constraints(self) ->
|
|
189
|
+
def serialization_constraints(self) -> list[str]:
|
|
190
190
|
validation_constraints = [
|
|
191
191
|
(f"maximum_ex={self.maximum}" if self.maximum is not None and self.exclusive_maximum else None),
|
|
192
192
|
(f"maximum={self.maximum}" if self.maximum is not None and not self.exclusive_maximum else None),
|
|
@@ -197,8 +197,8 @@ class NumberType(PrimitiveType):
|
|
|
197
197
|
return [x for x in validation_constraints if x is not None]
|
|
198
198
|
|
|
199
199
|
@property
|
|
200
|
-
def validation(self) -> Optional[
|
|
201
|
-
validation:
|
|
200
|
+
def validation(self) -> Optional[dict[str, Union[bool, int, str]]]:
|
|
201
|
+
validation: dict[str, Union[bool, int, str]] = {}
|
|
202
202
|
if self.maximum is not None:
|
|
203
203
|
if self.exclusive_maximum:
|
|
204
204
|
validation["maximum_ex"] = self.maximum
|
|
@@ -221,7 +221,7 @@ class NumberType(PrimitiveType):
|
|
|
221
221
|
|
|
222
222
|
class IntegerType(NumberType):
|
|
223
223
|
|
|
224
|
-
def __init__(self, yaml_data:
|
|
224
|
+
def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
|
|
225
225
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
226
226
|
if yaml_data.get("encode") == "string":
|
|
227
227
|
self.encode = "str"
|
|
@@ -294,7 +294,7 @@ class DecimalType(NumberType):
|
|
|
294
294
|
|
|
295
295
|
|
|
296
296
|
class StringType(PrimitiveType):
|
|
297
|
-
def __init__(self, yaml_data:
|
|
297
|
+
def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
|
|
298
298
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
299
299
|
self.max_length: Optional[int] = yaml_data.get("maxLength")
|
|
300
300
|
self.min_length: Optional[int] = (
|
|
@@ -303,7 +303,7 @@ class StringType(PrimitiveType):
|
|
|
303
303
|
self.pattern: Optional[str] = yaml_data.get("pattern")
|
|
304
304
|
|
|
305
305
|
@property
|
|
306
|
-
def serialization_constraints(self) ->
|
|
306
|
+
def serialization_constraints(self) -> list[str]:
|
|
307
307
|
validation_constraints = [
|
|
308
308
|
f"max_length={self.max_length}" if self.max_length is not None else None,
|
|
309
309
|
f"min_length={self.min_length}" if self.min_length is not None else None,
|
|
@@ -312,8 +312,8 @@ class StringType(PrimitiveType):
|
|
|
312
312
|
return [x for x in validation_constraints if x is not None]
|
|
313
313
|
|
|
314
314
|
@property
|
|
315
|
-
def validation(self) -> Optional[
|
|
316
|
-
validation:
|
|
315
|
+
def validation(self) -> Optional[dict[str, Union[bool, int, str]]]:
|
|
316
|
+
validation: dict[str, Union[bool, int, str]] = {}
|
|
317
317
|
if self.max_length is not None:
|
|
318
318
|
validation["max_length"] = self.max_length
|
|
319
319
|
if self.min_length is not None:
|
|
@@ -338,7 +338,7 @@ class StringType(PrimitiveType):
|
|
|
338
338
|
|
|
339
339
|
|
|
340
340
|
class DatetimeType(PrimitiveType):
|
|
341
|
-
def __init__(self, yaml_data:
|
|
341
|
+
def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
|
|
342
342
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
343
343
|
self.encode = (
|
|
344
344
|
"rfc3339"
|
|
@@ -564,7 +564,7 @@ class DurationType(PrimitiveType):
|
|
|
564
564
|
|
|
565
565
|
|
|
566
566
|
class ByteArraySchema(PrimitiveType):
|
|
567
|
-
def __init__(self, yaml_data:
|
|
567
|
+
def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
|
|
568
568
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
569
569
|
self.encode = yaml_data.get("encode", "base64")
|
|
570
570
|
|
|
@@ -585,20 +585,26 @@ class ByteArraySchema(PrimitiveType):
|
|
|
585
585
|
|
|
586
586
|
|
|
587
587
|
class SdkCoreType(PrimitiveType):
|
|
588
|
-
def __init__(self, yaml_data:
|
|
588
|
+
def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
|
|
589
589
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
590
590
|
self.name = yaml_data.get("name", "")
|
|
591
591
|
self.submodule = yaml_data.get("submodule", "")
|
|
592
|
+
self.is_typing_only = yaml_data.get("isTypingOnly", False)
|
|
592
593
|
|
|
593
594
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
594
|
-
return f"~{self.code_model.core_library}.{self.
|
|
595
|
+
return f"~{self.code_model.core_library}.{self.name}"
|
|
595
596
|
|
|
596
597
|
def type_annotation(self, **kwargs: Any) -> str:
|
|
597
|
-
return self.name
|
|
598
|
+
return f'"{self.name}"' if self.is_typing_only else self.name
|
|
598
599
|
|
|
599
600
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
600
601
|
file_import = super().imports(**kwargs)
|
|
601
|
-
file_import.add_submodule_import(
|
|
602
|
+
file_import.add_submodule_import(
|
|
603
|
+
self.submodule,
|
|
604
|
+
self.name,
|
|
605
|
+
ImportType.SDKCORE,
|
|
606
|
+
typing_section=TypingSection.TYPING if self.is_typing_only else TypingSection.REGULAR,
|
|
607
|
+
)
|
|
602
608
|
return file_import
|
|
603
609
|
|
|
604
610
|
@property
|
|
@@ -610,7 +616,7 @@ class SdkCoreType(PrimitiveType):
|
|
|
610
616
|
|
|
611
617
|
|
|
612
618
|
class MultiPartFileType(PrimitiveType):
|
|
613
|
-
def __init__(self, yaml_data:
|
|
619
|
+
def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
|
|
614
620
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
615
621
|
self.name = "FileType"
|
|
616
622
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import Any,
|
|
6
|
+
from typing import Any, Optional, TYPE_CHECKING, cast, Union
|
|
7
7
|
|
|
8
8
|
from .base import BaseModel
|
|
9
9
|
from .constant_type import ConstantType
|
|
@@ -20,7 +20,7 @@ if TYPE_CHECKING:
|
|
|
20
20
|
class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
21
21
|
def __init__(
|
|
22
22
|
self,
|
|
23
|
-
yaml_data:
|
|
23
|
+
yaml_data: dict[str, Any],
|
|
24
24
|
code_model: "CodeModel",
|
|
25
25
|
type: BaseType,
|
|
26
26
|
) -> None:
|
|
@@ -30,13 +30,13 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
30
30
|
self.type = type
|
|
31
31
|
self.optional: bool = self.yaml_data["optional"]
|
|
32
32
|
self.readonly: bool = self.yaml_data.get("readonly", False)
|
|
33
|
-
self.visibility:
|
|
33
|
+
self.visibility: list[str] = self.yaml_data.get("visibility", [])
|
|
34
34
|
self.is_polymorphic: bool = self.yaml_data.get("isPolymorphic", False)
|
|
35
35
|
self.is_discriminator: bool = yaml_data.get("isDiscriminator", False)
|
|
36
36
|
self.client_default_value = yaml_data.get("clientDefaultValue", None)
|
|
37
37
|
if self.client_default_value is None:
|
|
38
38
|
self.client_default_value = self.type.client_default_value
|
|
39
|
-
self.flattened_names:
|
|
39
|
+
self.flattened_names: list[str] = yaml_data.get("flattenedNames", [])
|
|
40
40
|
self.is_multipart_file_input: bool = yaml_data.get("isMultipartFileInput", False)
|
|
41
41
|
self.flatten = self.yaml_data.get("flatten", False) and not getattr(self.type, "flattened_property", False)
|
|
42
42
|
|
|
@@ -101,7 +101,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
101
101
|
return self.is_discriminator and self.is_polymorphic and cast(ConstantType, self.type).value is None
|
|
102
102
|
|
|
103
103
|
@property
|
|
104
|
-
def xml_metadata(self) -> Optional[
|
|
104
|
+
def xml_metadata(self) -> Optional[dict[str, Union[str, bool]]]:
|
|
105
105
|
return self.yaml_data.get("xmlMetadata")
|
|
106
106
|
|
|
107
107
|
def type_annotation(self, *, is_operation_file: bool = False, **kwargs: Any) -> str:
|
|
@@ -127,22 +127,22 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
127
127
|
client_default_value_declaration=client_default_value_declaration,
|
|
128
128
|
)
|
|
129
129
|
|
|
130
|
-
def get_polymorphic_subtypes(self, polymorphic_subtypes:
|
|
130
|
+
def get_polymorphic_subtypes(self, polymorphic_subtypes: list["ModelType"]) -> None:
|
|
131
131
|
from .model_type import ModelType
|
|
132
132
|
|
|
133
133
|
if isinstance(self.type, ModelType):
|
|
134
134
|
self.type.get_polymorphic_subtypes(polymorphic_subtypes)
|
|
135
135
|
|
|
136
136
|
@property
|
|
137
|
-
def validation(self) -> Optional[
|
|
138
|
-
retval:
|
|
137
|
+
def validation(self) -> Optional[dict[str, Any]]:
|
|
138
|
+
retval: dict[str, Any] = {}
|
|
139
139
|
if not self.optional:
|
|
140
140
|
retval["required"] = True
|
|
141
141
|
if self.readonly:
|
|
142
142
|
retval["readonly"] = True
|
|
143
143
|
if self.constant:
|
|
144
144
|
retval["constant"] = True
|
|
145
|
-
retval
|
|
145
|
+
retval |= self.type.validation or {}
|
|
146
146
|
return retval or None
|
|
147
147
|
|
|
148
148
|
def imports(self, **kwargs) -> FileImport:
|
|
@@ -164,7 +164,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
164
164
|
@classmethod
|
|
165
165
|
def from_yaml(
|
|
166
166
|
cls,
|
|
167
|
-
yaml_data:
|
|
167
|
+
yaml_data: dict[str, Any],
|
|
168
168
|
code_model: "CodeModel",
|
|
169
169
|
) -> "Property":
|
|
170
170
|
from . import build_type # pylint: disable=import-outside-toplevel
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
from typing import (
|
|
7
7
|
Any,
|
|
8
8
|
Callable,
|
|
9
|
-
Dict,
|
|
10
9
|
TypeVar,
|
|
11
10
|
TYPE_CHECKING,
|
|
12
11
|
Union,
|
|
@@ -38,7 +37,7 @@ ParameterListType = TypeVar(
|
|
|
38
37
|
class RequestBuilderBase(BaseBuilder[ParameterListType, Sequence["RequestBuilder"]]):
|
|
39
38
|
def __init__(
|
|
40
39
|
self,
|
|
41
|
-
yaml_data:
|
|
40
|
+
yaml_data: dict[str, Any],
|
|
42
41
|
code_model: "CodeModel",
|
|
43
42
|
client: "Client",
|
|
44
43
|
name: str,
|
|
@@ -116,13 +115,13 @@ class RequestBuilderBase(BaseBuilder[ParameterListType, Sequence["RequestBuilder
|
|
|
116
115
|
|
|
117
116
|
@staticmethod
|
|
118
117
|
@abstractmethod
|
|
119
|
-
def parameter_list_type() -> Callable[[
|
|
118
|
+
def parameter_list_type() -> Callable[[dict[str, Any], "CodeModel"], ParameterListType]: ...
|
|
120
119
|
|
|
121
120
|
@classmethod
|
|
122
121
|
def get_name(
|
|
123
122
|
cls,
|
|
124
123
|
name: str,
|
|
125
|
-
yaml_data:
|
|
124
|
+
yaml_data: dict[str, Any],
|
|
126
125
|
code_model: "CodeModel",
|
|
127
126
|
client: "Client",
|
|
128
127
|
) -> str:
|
|
@@ -140,7 +139,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType, Sequence["RequestBuilder
|
|
|
140
139
|
@classmethod
|
|
141
140
|
def from_yaml(
|
|
142
141
|
cls,
|
|
143
|
-
yaml_data:
|
|
142
|
+
yaml_data: dict[str, Any],
|
|
144
143
|
code_model: "CodeModel",
|
|
145
144
|
client: "Client",
|
|
146
145
|
):
|
|
@@ -165,18 +164,18 @@ class RequestBuilderBase(BaseBuilder[ParameterListType, Sequence["RequestBuilder
|
|
|
165
164
|
|
|
166
165
|
class RequestBuilder(RequestBuilderBase[RequestBuilderParameterList]):
|
|
167
166
|
@staticmethod
|
|
168
|
-
def parameter_list_type() -> Callable[[
|
|
167
|
+
def parameter_list_type() -> Callable[[dict[str, Any], "CodeModel"], RequestBuilderParameterList]:
|
|
169
168
|
return RequestBuilderParameterList.from_yaml
|
|
170
169
|
|
|
171
170
|
|
|
172
171
|
class OverloadedRequestBuilder(RequestBuilderBase[OverloadedRequestBuilderParameterList]):
|
|
173
172
|
@staticmethod
|
|
174
|
-
def parameter_list_type() -> Callable[[
|
|
173
|
+
def parameter_list_type() -> Callable[[dict[str, Any], "CodeModel"], OverloadedRequestBuilderParameterList]:
|
|
175
174
|
return OverloadedRequestBuilderParameterList.from_yaml
|
|
176
175
|
|
|
177
176
|
|
|
178
177
|
def get_request_builder(
|
|
179
|
-
yaml_data:
|
|
178
|
+
yaml_data: dict[str, Any], code_model: "CodeModel", client: "Client"
|
|
180
179
|
) -> Union[RequestBuilder, OverloadedRequestBuilder]:
|
|
181
180
|
if yaml_data.get("overloads"):
|
|
182
181
|
return OverloadedRequestBuilder.from_yaml(yaml_data, code_model, client)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import TYPE_CHECKING, Any
|
|
6
|
+
from typing import TYPE_CHECKING, Any
|
|
7
7
|
from .parameter import (
|
|
8
8
|
ParameterLocation,
|
|
9
9
|
ParameterMethodLocation,
|
|
@@ -52,7 +52,7 @@ class RequestBuilderBodyParameter(BodyParameter):
|
|
|
52
52
|
)
|
|
53
53
|
|
|
54
54
|
@classmethod
|
|
55
|
-
def from_yaml(cls, yaml_data:
|
|
55
|
+
def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "RequestBuilderBodyParameter":
|
|
56
56
|
return super().from_yaml(yaml_data, code_model) # type: ignore
|
|
57
57
|
|
|
58
58
|
@property
|
|
@@ -67,7 +67,7 @@ class RequestBuilderParameter(Parameter):
|
|
|
67
67
|
|
|
68
68
|
def __init__(
|
|
69
69
|
self,
|
|
70
|
-
yaml_data:
|
|
70
|
+
yaml_data: dict[str, Any],
|
|
71
71
|
code_model: "CodeModel",
|
|
72
72
|
type: BaseType,
|
|
73
73
|
) -> None:
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import
|
|
6
|
+
from typing import Optional, Any, TYPE_CHECKING, Union
|
|
7
7
|
|
|
8
8
|
from .base import BaseModel
|
|
9
9
|
from .base import BaseType
|
|
@@ -21,7 +21,7 @@ if TYPE_CHECKING:
|
|
|
21
21
|
class ResponseHeader(BaseModel):
|
|
22
22
|
def __init__(
|
|
23
23
|
self,
|
|
24
|
-
yaml_data:
|
|
24
|
+
yaml_data: dict[str, Any],
|
|
25
25
|
code_model: "CodeModel",
|
|
26
26
|
type: BaseType,
|
|
27
27
|
) -> None:
|
|
@@ -33,7 +33,7 @@ class ResponseHeader(BaseModel):
|
|
|
33
33
|
return self.type.serialization_type(**kwargs)
|
|
34
34
|
|
|
35
35
|
@classmethod
|
|
36
|
-
def from_yaml(cls, yaml_data:
|
|
36
|
+
def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "ResponseHeader":
|
|
37
37
|
from . import build_type
|
|
38
38
|
|
|
39
39
|
return cls(
|
|
@@ -46,14 +46,14 @@ class ResponseHeader(BaseModel):
|
|
|
46
46
|
class Response(BaseModel):
|
|
47
47
|
def __init__(
|
|
48
48
|
self,
|
|
49
|
-
yaml_data:
|
|
49
|
+
yaml_data: dict[str, Any],
|
|
50
50
|
code_model: "CodeModel",
|
|
51
51
|
*,
|
|
52
|
-
headers: Optional[
|
|
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
|
-
self.status_codes:
|
|
56
|
+
self.status_codes: list[Union[int, str, list[int]]] = yaml_data["statusCodes"]
|
|
57
57
|
self.headers = headers or []
|
|
58
58
|
self.type = type
|
|
59
59
|
self.nullable = yaml_data.get("nullable")
|
|
@@ -66,7 +66,7 @@ class Response(BaseModel):
|
|
|
66
66
|
return "".join([f'.get("{field}", {{}})' for field in field.split(".")])
|
|
67
67
|
return ""
|
|
68
68
|
|
|
69
|
-
def get_polymorphic_subtypes(self, polymorphic_subtypes:
|
|
69
|
+
def get_polymorphic_subtypes(self, polymorphic_subtypes: list["ModelType"]) -> None:
|
|
70
70
|
if self.type:
|
|
71
71
|
self.type.get_polymorphic_subtypes(polymorphic_subtypes)
|
|
72
72
|
|
|
@@ -111,7 +111,7 @@ class Response(BaseModel):
|
|
|
111
111
|
return f"{self.type.docstring_type(**kwargs)} or None"
|
|
112
112
|
return self.type.docstring_type(**kwargs) if self.type else "None"
|
|
113
113
|
|
|
114
|
-
def
|
|
114
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
115
115
|
file_import = FileImport(self.code_model)
|
|
116
116
|
if self.type:
|
|
117
117
|
file_import.merge(self.type.imports(**kwargs))
|
|
@@ -127,12 +127,6 @@ class Response(BaseModel):
|
|
|
127
127
|
)
|
|
128
128
|
return file_import
|
|
129
129
|
|
|
130
|
-
def imports(self, **kwargs: Any) -> FileImport:
|
|
131
|
-
return self._imports_shared(**kwargs)
|
|
132
|
-
|
|
133
|
-
def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
|
|
134
|
-
return self._imports_shared(**kwargs)
|
|
135
|
-
|
|
136
130
|
def _get_import_type(self, input_path: str) -> ImportType:
|
|
137
131
|
# helper function to return imports for responses based off
|
|
138
132
|
# of whether we're importing from the core library, or users
|
|
@@ -140,7 +134,7 @@ class Response(BaseModel):
|
|
|
140
134
|
return ImportType.SDKCORE if self.code_model.core_library.split(".")[0] in input_path else ImportType.THIRDPARTY
|
|
141
135
|
|
|
142
136
|
@classmethod
|
|
143
|
-
def from_yaml(cls, yaml_data:
|
|
137
|
+
def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "Response":
|
|
144
138
|
type = code_model.lookup_type(id(yaml_data["type"])) if yaml_data.get("type") else None
|
|
145
139
|
# use ByteIteratorType if we are returning a binary type
|
|
146
140
|
default_content_type = yaml_data.get("defaultContentType", "application/json")
|
|
@@ -170,7 +164,7 @@ class PagingResponse(Response):
|
|
|
170
164
|
or f"{self.code_model.core_library}.{default_paging_submodule}.AsyncItemPaged"
|
|
171
165
|
)
|
|
172
166
|
|
|
173
|
-
def get_polymorphic_subtypes(self, polymorphic_subtypes:
|
|
167
|
+
def get_polymorphic_subtypes(self, polymorphic_subtypes: list["ModelType"]) -> None:
|
|
174
168
|
return self.item_type.get_polymorphic_subtypes(polymorphic_subtypes)
|
|
175
169
|
|
|
176
170
|
def get_json_template_representation(self) -> Any:
|
|
@@ -198,17 +192,13 @@ class PagingResponse(Response):
|
|
|
198
192
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
199
193
|
return f"~{self.get_pager_path(kwargs['async_mode'])}[{self.item_type.docstring_type(**kwargs)}]"
|
|
200
194
|
|
|
201
|
-
def
|
|
202
|
-
file_import = super().
|
|
195
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
196
|
+
file_import = super().imports(**kwargs)
|
|
203
197
|
async_mode = kwargs.get("async_mode", False)
|
|
204
198
|
pager = self.get_pager(async_mode)
|
|
205
199
|
pager_path = self.get_pager_import_path(async_mode)
|
|
206
200
|
|
|
207
201
|
file_import.add_submodule_import(pager_path, pager, self._get_import_type(pager_path))
|
|
208
|
-
return file_import
|
|
209
|
-
|
|
210
|
-
def imports(self, **kwargs: Any) -> FileImport:
|
|
211
|
-
file_import = self._imports_shared(**kwargs)
|
|
212
202
|
async_mode = kwargs.get("async_mode")
|
|
213
203
|
if async_mode:
|
|
214
204
|
file_import.add_submodule_import(
|
|
@@ -219,9 +209,6 @@ class PagingResponse(Response):
|
|
|
219
209
|
|
|
220
210
|
return file_import
|
|
221
211
|
|
|
222
|
-
def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
|
|
223
|
-
return self._imports_shared(**kwargs)
|
|
224
|
-
|
|
225
212
|
|
|
226
213
|
class LROResponse(Response):
|
|
227
214
|
def get_poller_path(self, async_mode: bool) -> str:
|
|
@@ -270,16 +257,12 @@ class LROResponse(Response):
|
|
|
270
257
|
base_description += "either "
|
|
271
258
|
return base_description + super_text
|
|
272
259
|
|
|
273
|
-
def
|
|
274
|
-
file_import = super().
|
|
260
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
261
|
+
file_import = super().imports(**kwargs)
|
|
275
262
|
async_mode = kwargs["async_mode"]
|
|
276
263
|
poller_import_path = ".".join(self.get_poller_path(async_mode).split(".")[:-1])
|
|
277
264
|
poller = self.get_poller(async_mode)
|
|
278
265
|
file_import.add_submodule_import(poller_import_path, poller, self._get_import_type(poller_import_path))
|
|
279
|
-
return file_import
|
|
280
|
-
|
|
281
|
-
def imports(self, **kwargs: Any) -> FileImport:
|
|
282
|
-
file_import = self._imports_shared(**kwargs)
|
|
283
266
|
async_mode = kwargs["async_mode"]
|
|
284
267
|
|
|
285
268
|
default_polling_method_import_path = ".".join(self.get_polling_method_path(async_mode).split(".")[:-1])
|
|
@@ -306,9 +289,6 @@ class LROResponse(Response):
|
|
|
306
289
|
)
|
|
307
290
|
return file_import
|
|
308
291
|
|
|
309
|
-
def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
|
|
310
|
-
return self._imports_shared(**kwargs)
|
|
311
|
-
|
|
312
292
|
|
|
313
293
|
class LROPagingResponse(LROResponse, PagingResponse):
|
|
314
294
|
def type_annotation(self, **kwargs: Any) -> str:
|
|
@@ -325,18 +305,13 @@ class LROPagingResponse(LROResponse, PagingResponse):
|
|
|
325
305
|
base_description += "either "
|
|
326
306
|
return base_description + Response.docstring_text(self)
|
|
327
307
|
|
|
328
|
-
def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
|
|
329
|
-
file_import = LROResponse.imports_for_multiapi(self, **kwargs)
|
|
330
|
-
file_import.merge(PagingResponse.imports_for_multiapi(self, **kwargs))
|
|
331
|
-
return file_import
|
|
332
|
-
|
|
333
308
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
334
309
|
file_import = LROResponse.imports(self, **kwargs)
|
|
335
310
|
file_import.merge(PagingResponse.imports(self, **kwargs))
|
|
336
311
|
return file_import
|
|
337
312
|
|
|
338
313
|
|
|
339
|
-
def get_response(yaml_data:
|
|
314
|
+
def get_response(yaml_data: dict[str, Any], code_model: "CodeModel") -> Response:
|
|
340
315
|
if yaml_data["discriminator"] == "lropaging":
|
|
341
316
|
return LROPagingResponse.from_yaml(yaml_data, code_model)
|
|
342
317
|
if yaml_data["discriminator"] == "lro":
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import TypeVar
|
|
6
|
+
from typing import TypeVar
|
|
7
7
|
|
|
8
8
|
from enum import Enum
|
|
9
9
|
|
|
10
10
|
T = TypeVar("T")
|
|
11
|
-
OrderedSet =
|
|
11
|
+
OrderedSet = dict[T, None]
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def add_to_description(description: str, entry: str) -> str:
|