@autorest/python 5.15.0 → 5.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog.md +98 -4
- package/README.md +30 -4
- package/autorest/__init__.py +2 -3
- package/autorest/black/__init__.py +12 -5
- package/autorest/codegen/__init__.py +122 -211
- package/autorest/codegen/models/__init__.py +122 -78
- package/autorest/codegen/models/base_builder.py +70 -72
- package/autorest/codegen/models/base_model.py +7 -5
- package/autorest/codegen/models/{base_schema.py → base_type.py} +68 -45
- package/autorest/codegen/models/client.py +193 -40
- package/autorest/codegen/models/code_model.py +145 -245
- package/autorest/codegen/models/combined_type.py +107 -0
- package/autorest/codegen/models/constant_type.py +122 -0
- package/autorest/codegen/models/credential_types.py +224 -0
- package/autorest/codegen/models/dictionary_type.py +131 -0
- package/autorest/codegen/models/enum_type.py +195 -0
- package/autorest/codegen/models/imports.py +93 -41
- package/autorest/codegen/models/list_type.py +149 -0
- package/autorest/codegen/models/lro_operation.py +90 -133
- package/autorest/codegen/models/lro_paging_operation.py +28 -12
- package/autorest/codegen/models/model_type.py +262 -0
- package/autorest/codegen/models/operation.py +412 -259
- package/autorest/codegen/models/operation_group.py +80 -91
- package/autorest/codegen/models/paging_operation.py +101 -117
- package/autorest/codegen/models/parameter.py +302 -341
- package/autorest/codegen/models/parameter_list.py +373 -357
- package/autorest/codegen/models/primitive_types.py +544 -0
- package/autorest/codegen/models/property.py +136 -134
- package/autorest/codegen/models/request_builder.py +138 -86
- package/autorest/codegen/models/request_builder_parameter.py +122 -86
- package/autorest/codegen/models/response.py +325 -0
- package/autorest/codegen/models/utils.py +13 -17
- package/autorest/codegen/serializers/__init__.py +212 -112
- package/autorest/codegen/serializers/builder_serializer.py +931 -1040
- package/autorest/codegen/serializers/client_serializer.py +140 -84
- package/autorest/codegen/serializers/general_serializer.py +26 -50
- package/autorest/codegen/serializers/import_serializer.py +96 -31
- package/autorest/codegen/serializers/metadata_serializer.py +39 -79
- package/autorest/codegen/serializers/model_base_serializer.py +62 -34
- package/autorest/codegen/serializers/model_generic_serializer.py +9 -10
- package/autorest/codegen/serializers/model_init_serializer.py +4 -2
- package/autorest/codegen/serializers/model_python3_serializer.py +29 -22
- package/autorest/codegen/serializers/operation_groups_serializer.py +21 -19
- package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
- package/autorest/codegen/serializers/parameter_serializer.py +174 -0
- package/autorest/codegen/serializers/patch_serializer.py +4 -1
- package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
- package/autorest/codegen/serializers/utils.py +0 -126
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
- package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
- package/autorest/codegen/templates/config.py.jinja2 +13 -13
- package/autorest/codegen/templates/enum.py.jinja2 +4 -4
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/init.py.jinja2 +3 -3
- package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
- package/autorest/codegen/templates/model.py.jinja2 +23 -24
- package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
- package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
- package/autorest/codegen/templates/operation.py.jinja2 +10 -14
- package/autorest/codegen/templates/operation_group.py.jinja2 +9 -15
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
- package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
- package/autorest/codegen/templates/request_builder.py.jinja2 +19 -10
- package/autorest/codegen/templates/setup.py.jinja2 +9 -3
- package/autorest/codegen/templates/vendor.py.jinja2 +1 -1
- package/autorest/jsonrpc/__init__.py +7 -12
- package/autorest/jsonrpc/localapi.py +4 -3
- package/autorest/jsonrpc/server.py +28 -9
- package/autorest/jsonrpc/stdstream.py +13 -6
- package/autorest/m2r/__init__.py +5 -8
- package/autorest/m4reformatter/__init__.py +1126 -0
- package/autorest/multiapi/__init__.py +24 -14
- package/autorest/multiapi/models/client.py +21 -11
- package/autorest/multiapi/models/code_model.py +23 -10
- package/autorest/multiapi/models/config.py +4 -1
- package/autorest/multiapi/models/constant_global_parameter.py +1 -0
- package/autorest/multiapi/models/global_parameter.py +2 -1
- package/autorest/multiapi/models/global_parameters.py +14 -8
- package/autorest/multiapi/models/imports.py +24 -17
- package/autorest/multiapi/models/mixin_operation.py +5 -5
- package/autorest/multiapi/models/operation_group.py +2 -1
- package/autorest/multiapi/models/operation_mixin_group.py +21 -10
- package/autorest/multiapi/serializers/__init__.py +20 -25
- package/autorest/multiapi/serializers/import_serializer.py +47 -17
- package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
- package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
- package/autorest/multiapi/utils.py +3 -3
- package/autorest/postprocess/__init__.py +202 -0
- package/autorest/postprocess/get_all.py +19 -0
- package/autorest/postprocess/venvtools.py +73 -0
- package/autorest/preprocess/__init__.py +210 -0
- package/autorest/preprocess/helpers.py +54 -0
- package/autorest/{namer → preprocess}/python_mappings.py +25 -32
- package/package.json +3 -3
- package/run-python3.js +2 -3
- package/venvtools.py +1 -1
- package/autorest/codegen/models/constant_schema.py +0 -101
- package/autorest/codegen/models/credential_model.py +0 -47
- package/autorest/codegen/models/credential_schema.py +0 -91
- package/autorest/codegen/models/credential_schema_policy.py +0 -77
- package/autorest/codegen/models/dictionary_schema.py +0 -103
- package/autorest/codegen/models/enum_schema.py +0 -215
- package/autorest/codegen/models/list_schema.py +0 -123
- package/autorest/codegen/models/object_schema.py +0 -253
- package/autorest/codegen/models/primitive_schemas.py +0 -466
- package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
- package/autorest/codegen/models/rest.py +0 -42
- package/autorest/codegen/models/schema_request.py +0 -45
- package/autorest/codegen/models/schema_response.py +0 -136
- package/autorest/codegen/serializers/rest_serializer.py +0 -57
- package/autorest/namer/__init__.py +0 -25
- package/autorest/namer/name_converter.py +0 -412
|
@@ -3,120 +3,164 @@
|
|
|
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, Dict
|
|
6
|
+
from typing import Any, Dict, Union
|
|
7
7
|
from .base_model import BaseModel
|
|
8
8
|
from .code_model import CodeModel
|
|
9
|
-
from .
|
|
10
|
-
from .
|
|
11
|
-
from .
|
|
12
|
-
from .
|
|
13
|
-
from .
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
from .model_type import ModelType
|
|
10
|
+
from .dictionary_type import DictionaryType
|
|
11
|
+
from .list_type import ListType
|
|
12
|
+
from .combined_type import CombinedType
|
|
13
|
+
from .primitive_types import (
|
|
14
|
+
ByteArraySchema,
|
|
15
|
+
DateType,
|
|
16
|
+
DatetimeType,
|
|
17
|
+
DurationType,
|
|
18
|
+
IntegerType,
|
|
19
|
+
FloatType,
|
|
20
|
+
StringType,
|
|
21
|
+
TimeType,
|
|
22
|
+
AnyType,
|
|
23
|
+
PrimitiveType,
|
|
24
|
+
BinaryType,
|
|
25
|
+
BooleanType,
|
|
26
|
+
AnyObjectType,
|
|
27
|
+
UnixTimeType,
|
|
28
|
+
)
|
|
29
|
+
from .enum_type import EnumType
|
|
30
|
+
from .base_type import BaseType
|
|
31
|
+
from .constant_type import ConstantType
|
|
17
32
|
from .imports import FileImport, ImportType, TypingSection
|
|
18
33
|
from .lro_operation import LROOperation
|
|
19
34
|
from .paging_operation import PagingOperation
|
|
20
|
-
from .parameter import
|
|
35
|
+
from .parameter import (
|
|
36
|
+
Parameter,
|
|
37
|
+
ParameterMethodLocation,
|
|
38
|
+
ParameterLocation,
|
|
39
|
+
BodyParameter,
|
|
40
|
+
ParameterDelimeter,
|
|
41
|
+
MultipartBodyParameter,
|
|
42
|
+
ClientParameter,
|
|
43
|
+
ConfigParameter,
|
|
44
|
+
)
|
|
21
45
|
from .operation import Operation
|
|
22
46
|
from .property import Property
|
|
23
47
|
from .operation_group import OperationGroup
|
|
24
|
-
from .
|
|
25
|
-
from .parameter_list import
|
|
26
|
-
|
|
48
|
+
from .response import Response
|
|
49
|
+
from .parameter_list import (
|
|
50
|
+
ParameterList,
|
|
51
|
+
ClientGlobalParameterList,
|
|
52
|
+
ConfigGlobalParameterList,
|
|
53
|
+
)
|
|
54
|
+
from .request_builder import (
|
|
55
|
+
RequestBuilder,
|
|
56
|
+
OverloadedRequestBuilder,
|
|
57
|
+
RequestBuilderBase,
|
|
58
|
+
)
|
|
27
59
|
from .base_builder import BaseBuilder
|
|
28
60
|
from .lro_paging_operation import LROPagingOperation
|
|
29
|
-
from .request_builder_parameter import
|
|
30
|
-
|
|
61
|
+
from .request_builder_parameter import (
|
|
62
|
+
RequestBuilderParameter,
|
|
63
|
+
RequestBuilderBodyParameter,
|
|
64
|
+
)
|
|
65
|
+
from .credential_types import (
|
|
66
|
+
TokenCredentialType,
|
|
67
|
+
AzureKeyCredentialType,
|
|
68
|
+
ARMChallengeAuthenticationPolicyType,
|
|
69
|
+
BearerTokenCredentialPolicyType,
|
|
70
|
+
AzureKeyCredentialPolicyType,
|
|
71
|
+
CredentialType,
|
|
72
|
+
)
|
|
31
73
|
|
|
32
74
|
__all__ = [
|
|
33
|
-
"
|
|
34
|
-
"
|
|
75
|
+
"AzureKeyCredentialPolicyType",
|
|
76
|
+
"AnyType",
|
|
35
77
|
"BaseModel",
|
|
36
|
-
"
|
|
78
|
+
"BaseType",
|
|
37
79
|
"CodeModel",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"HiddenModelEnumSchema",
|
|
80
|
+
"ConstantType",
|
|
81
|
+
"ModelType",
|
|
82
|
+
"DictionaryType",
|
|
83
|
+
"ListType",
|
|
84
|
+
"EnumType",
|
|
44
85
|
"FileImport",
|
|
45
86
|
"ImportType",
|
|
46
87
|
"TypingSection",
|
|
47
|
-
"
|
|
88
|
+
"PrimitiveType",
|
|
48
89
|
"LROOperation",
|
|
49
90
|
"Operation",
|
|
50
91
|
"PagingOperation",
|
|
51
92
|
"Parameter",
|
|
52
93
|
"ParameterList",
|
|
53
|
-
"ParameterLocation",
|
|
54
94
|
"OperationGroup",
|
|
55
95
|
"Property",
|
|
56
96
|
"RequestBuilder",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
97
|
+
"Response",
|
|
98
|
+
"TokenCredentialType",
|
|
59
99
|
"LROPagingOperation",
|
|
60
100
|
"BaseBuilder",
|
|
61
|
-
"SchemaRequest",
|
|
62
101
|
"RequestBuilderParameter",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
102
|
+
"BinaryType",
|
|
103
|
+
"ClientGlobalParameterList",
|
|
104
|
+
"ConfigGlobalParameterList",
|
|
105
|
+
"ParameterMethodLocation",
|
|
106
|
+
"ParameterLocation",
|
|
107
|
+
"OverloadedRequestBuilder",
|
|
108
|
+
"RequestBuilderBase",
|
|
109
|
+
"BodyParameter",
|
|
110
|
+
"RequestBuilderBodyParameter",
|
|
111
|
+
"ParameterDelimeter",
|
|
112
|
+
"MultipartBodyParameter",
|
|
113
|
+
"CredentialType",
|
|
114
|
+
"ClientParameter",
|
|
115
|
+
"ConfigParameter",
|
|
67
116
|
]
|
|
68
117
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
118
|
+
TYPE_TO_OBJECT = {
|
|
119
|
+
"integer": IntegerType,
|
|
120
|
+
"float": FloatType,
|
|
121
|
+
"string": StringType,
|
|
122
|
+
"list": ListType,
|
|
123
|
+
"dict": DictionaryType,
|
|
124
|
+
"constant": ConstantType,
|
|
125
|
+
"enum": EnumType,
|
|
126
|
+
"binary": BinaryType,
|
|
127
|
+
"any": AnyType,
|
|
128
|
+
"datetime": DatetimeType,
|
|
129
|
+
"time": TimeType,
|
|
130
|
+
"duration": DurationType,
|
|
131
|
+
"date": DateType,
|
|
132
|
+
"byte-array": ByteArraySchema,
|
|
133
|
+
"boolean": BooleanType,
|
|
134
|
+
"combined": CombinedType,
|
|
135
|
+
"OAuth2": TokenCredentialType,
|
|
136
|
+
"Key": AzureKeyCredentialType,
|
|
137
|
+
"ARMChallengeAuthenticationPolicy": ARMChallengeAuthenticationPolicyType,
|
|
138
|
+
"BearerTokenCredentialPolicy": BearerTokenCredentialPolicyType,
|
|
139
|
+
"AzureKeyCredentialPolicy": AzureKeyCredentialPolicyType,
|
|
140
|
+
"any-object": AnyObjectType,
|
|
141
|
+
"unixtime": UnixTimeType,
|
|
142
|
+
}
|
|
77
143
|
|
|
78
144
|
|
|
79
|
-
def
|
|
80
|
-
code_model = kwargs.get("code_model", None)
|
|
81
|
-
if not code_model:
|
|
82
|
-
raise ValueError("CodeModel not passed through kwargs")
|
|
145
|
+
def build_type(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseType:
|
|
83
146
|
yaml_id = id(yaml_data)
|
|
84
|
-
namespace = code_model.namespace
|
|
85
147
|
try:
|
|
86
|
-
return code_model.
|
|
148
|
+
return code_model.lookup_type(yaml_id)
|
|
87
149
|
except KeyError:
|
|
88
150
|
# Not created yet, let's create it and add it to the index
|
|
89
151
|
pass
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
elif schema_type in ["choice", "sealed-choice"]:
|
|
97
|
-
schema = get_enum_schema(code_model).from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
|
|
98
|
-
code_model.enums[yaml_id] = schema
|
|
99
|
-
|
|
100
|
-
elif schema_type == "array":
|
|
101
|
-
schema = ListSchema.from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
|
|
102
|
-
code_model.primitives[yaml_id] = schema
|
|
103
|
-
|
|
104
|
-
elif schema_type == "dictionary":
|
|
105
|
-
schema = DictionarySchema.from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
|
|
106
|
-
code_model.primitives[yaml_id] = schema
|
|
107
|
-
|
|
108
|
-
elif schema_type in ["object", "and", "group", "any-object"]:
|
|
109
|
-
if _generate_as_object_schema(yaml_data):
|
|
110
|
-
# To avoid infinite loop, create the right instance in memory,
|
|
111
|
-
# put it in the index, and then parse the object.
|
|
112
|
-
schema = get_object_schema(code_model)(namespace, yaml_data, "_", "")
|
|
113
|
-
code_model.schemas[yaml_id] = schema
|
|
114
|
-
schema.fill_instance_from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
|
|
115
|
-
else:
|
|
116
|
-
schema = AnySchema.from_yaml(namespace=namespace, yaml_data=yaml_data)
|
|
117
|
-
code_model.primitives[yaml_id] = schema
|
|
152
|
+
if yaml_data["type"] == "model":
|
|
153
|
+
# need to special case model to avoid recursion
|
|
154
|
+
response = ModelType(yaml_data, code_model)
|
|
155
|
+
code_model.types_map[yaml_id] = response
|
|
156
|
+
response.fill_instance_from_yaml(yaml_data, code_model)
|
|
118
157
|
else:
|
|
119
|
-
|
|
120
|
-
|
|
158
|
+
response = TYPE_TO_OBJECT[yaml_data["type"]].from_yaml(yaml_data, code_model) # type: ignore
|
|
159
|
+
code_model.types_map[yaml_id] = response
|
|
160
|
+
return response
|
|
121
161
|
|
|
122
|
-
|
|
162
|
+
|
|
163
|
+
RequestBuilderType = Union[RequestBuilder, OverloadedRequestBuilder]
|
|
164
|
+
ParameterType = Union[
|
|
165
|
+
Parameter, RequestBuilderParameter, ClientParameter, ConfigParameter
|
|
166
|
+
]
|
|
@@ -3,95 +3,93 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from
|
|
6
|
+
from abc import abstractmethod
|
|
7
|
+
from typing import Any, Dict, List, Optional, TypeVar, Union, TYPE_CHECKING, Generic
|
|
7
8
|
from .base_model import BaseModel
|
|
8
|
-
from .
|
|
9
|
-
|
|
9
|
+
from .parameter_list import (
|
|
10
|
+
ParameterList,
|
|
11
|
+
RequestBuilderParameterList,
|
|
12
|
+
OverloadedRequestBuilderParameterList,
|
|
13
|
+
)
|
|
10
14
|
|
|
15
|
+
ParameterListType = TypeVar(
|
|
16
|
+
"ParameterListType",
|
|
17
|
+
bound=Union[
|
|
18
|
+
ParameterList,
|
|
19
|
+
RequestBuilderParameterList,
|
|
20
|
+
OverloadedRequestBuilderParameterList,
|
|
21
|
+
],
|
|
22
|
+
)
|
|
11
23
|
|
|
12
|
-
_M4_HEADER_PARAMETERS = ["content_type", "accept"]
|
|
13
24
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
if TYPE_CHECKING:
|
|
26
|
+
from .code_model import CodeModel
|
|
27
|
+
from .operation import Operation
|
|
28
|
+
from .request_builder import RequestBuilder
|
|
18
29
|
|
|
19
|
-
multiple_content_type_parameters = []
|
|
20
|
-
parameters = [
|
|
21
|
-
parameter_creator(yaml, code_model=code_model)
|
|
22
|
-
for yaml in yaml_data.get("parameters", [])
|
|
23
|
-
]
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
for yaml in request.get("parameters", []):
|
|
27
|
-
parameter = parameter_creator(yaml, code_model=code_model)
|
|
28
|
-
name = yaml["language"]["python"]["name"]
|
|
29
|
-
if name in _M4_HEADER_PARAMETERS:
|
|
30
|
-
parameters.append(parameter)
|
|
31
|
-
elif multiple_requests:
|
|
32
|
-
parameter.has_multiple_content_types = True
|
|
33
|
-
multiple_content_type_parameters.append(parameter)
|
|
34
|
-
else:
|
|
35
|
-
parameters.append(parameter)
|
|
36
|
-
|
|
37
|
-
if multiple_content_type_parameters:
|
|
38
|
-
body_parameters_name_set = set(
|
|
39
|
-
p.serialized_name for p in multiple_content_type_parameters
|
|
40
|
-
)
|
|
41
|
-
if len(body_parameters_name_set) > 1:
|
|
42
|
-
raise ValueError(
|
|
43
|
-
f"The body parameter with multiple media types has different names: {body_parameters_name_set}"
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
parameters_index = {id(parameter.yaml_data): parameter for parameter in parameters}
|
|
48
|
-
|
|
49
|
-
# Need to connect the groupBy and originalParameter
|
|
50
|
-
for parameter in parameters:
|
|
51
|
-
parameter_grouped_by_id = id(parameter.grouped_by)
|
|
52
|
-
if parameter_grouped_by_id in parameters_index:
|
|
53
|
-
parameter.grouped_by = parameters_index[parameter_grouped_by_id]
|
|
54
|
-
|
|
55
|
-
parameter_original_id = id(parameter.original_parameter)
|
|
56
|
-
if parameter_original_id in parameters_index:
|
|
57
|
-
parameter.original_parameter = parameters_index[parameter_original_id]
|
|
58
|
-
|
|
59
|
-
return parameters, multiple_content_type_parameters
|
|
60
|
-
|
|
61
|
-
class BaseBuilder(BaseModel):
|
|
31
|
+
class BaseBuilder(Generic[ParameterListType], BaseModel):
|
|
62
32
|
"""Base class for Operations and Request Builders"""
|
|
63
33
|
|
|
64
34
|
def __init__(
|
|
65
35
|
self,
|
|
66
|
-
code_model,
|
|
67
36
|
yaml_data: Dict[str, Any],
|
|
37
|
+
code_model: "CodeModel",
|
|
68
38
|
name: str,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
39
|
+
parameters: ParameterListType,
|
|
40
|
+
*,
|
|
41
|
+
overloads=None,
|
|
42
|
+
abstract: bool = False,
|
|
43
|
+
want_tracing: bool = True,
|
|
74
44
|
) -> None:
|
|
75
|
-
super().__init__(yaml_data=yaml_data)
|
|
76
|
-
self.code_model = code_model
|
|
45
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
77
46
|
self.name = name
|
|
78
|
-
self.
|
|
47
|
+
self._description: str = yaml_data.get("description", "")
|
|
79
48
|
self.parameters = parameters
|
|
80
|
-
self.
|
|
81
|
-
|
|
82
|
-
|
|
49
|
+
self.overloads: Union[List["Operation"], List["RequestBuilder"]] = (
|
|
50
|
+
overloads or []
|
|
51
|
+
)
|
|
52
|
+
self._summary: str = yaml_data.get("summary", "")
|
|
53
|
+
# for operations where we don't know what to do, we mark them as abstract so users implement
|
|
54
|
+
# in patch.py
|
|
55
|
+
self.abstract = abstract
|
|
56
|
+
self.want_tracing = want_tracing
|
|
57
|
+
self.group_name: str = yaml_data["groupName"]
|
|
58
|
+
self.is_overload: bool = yaml_data["isOverload"]
|
|
59
|
+
self.api_versions: List[str] = yaml_data["apiVersions"]
|
|
83
60
|
|
|
84
61
|
@property
|
|
85
|
-
def
|
|
86
|
-
|
|
62
|
+
def summary(self) -> Optional[str]:
|
|
63
|
+
if self.abstract:
|
|
64
|
+
return None
|
|
65
|
+
return self._summary
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def pylint_disable(self) -> str:
|
|
69
|
+
return ""
|
|
70
|
+
|
|
71
|
+
@abstractmethod
|
|
72
|
+
def response_type_annotation(self, **kwargs) -> str:
|
|
73
|
+
...
|
|
74
|
+
|
|
75
|
+
@abstractmethod
|
|
76
|
+
def response_docstring_text(self, **kwargs) -> str:
|
|
77
|
+
...
|
|
87
78
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return response
|
|
92
|
-
raise ValueError(f"Incorrect status code {status_code}, operation {self.name}")
|
|
79
|
+
@abstractmethod
|
|
80
|
+
def response_docstring_type(self, **kwargs) -> str:
|
|
81
|
+
...
|
|
93
82
|
|
|
94
83
|
@property
|
|
95
|
-
def
|
|
96
|
-
|
|
97
|
-
|
|
84
|
+
def description(self) -> str:
|
|
85
|
+
if self.abstract:
|
|
86
|
+
return (
|
|
87
|
+
f'You need to write a custom operation for "{self.name}". Please refer to '
|
|
88
|
+
"https://aka.ms/azsdk/python/dpcodegen/python/customize to learn how to customize."
|
|
89
|
+
)
|
|
90
|
+
return self._description or self.name
|
|
91
|
+
|
|
92
|
+
def method_signature(self, is_python3_file: bool, async_mode: bool) -> List[str]:
|
|
93
|
+
if self.abstract:
|
|
94
|
+
return ["*args,", "**kwargs"]
|
|
95
|
+
return self.parameters.method_signature(is_python3_file, async_mode)
|
|
@@ -3,20 +3,22 @@
|
|
|
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, Dict
|
|
6
|
+
from typing import Any, Dict, TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from .code_model import CodeModel
|
|
7
10
|
|
|
8
11
|
|
|
9
12
|
class BaseModel:
|
|
10
|
-
"""This is the base class for model that are based on some YAML data.
|
|
13
|
+
"""This is the base class for model representations that are based on some YAML data.
|
|
11
14
|
|
|
12
15
|
:param yaml_data: the yaml data for this schema
|
|
13
16
|
:type yaml_data: dict[str, Any]
|
|
14
17
|
"""
|
|
15
18
|
|
|
16
|
-
def __init__(
|
|
17
|
-
self, yaml_data: Dict[str, Any],
|
|
18
|
-
) -> None:
|
|
19
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
19
20
|
self.yaml_data = yaml_data
|
|
21
|
+
self.code_model = code_model
|
|
20
22
|
|
|
21
23
|
@property
|
|
22
24
|
def id(self) -> int:
|
|
@@ -4,40 +4,52 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
from abc import ABC, abstractmethod
|
|
7
|
-
from typing import Any, Dict, List, Optional,
|
|
7
|
+
from typing import Any, Dict, List, Optional, TYPE_CHECKING
|
|
8
8
|
|
|
9
9
|
from .base_model import BaseModel
|
|
10
10
|
from .imports import FileImport
|
|
11
11
|
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from .code_model import CodeModel
|
|
14
|
+
from .model_type import ModelType
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
|
|
17
|
+
class BaseType(BaseModel, ABC):
|
|
18
|
+
"""This is the base class for all types.
|
|
15
19
|
|
|
16
20
|
:param yaml_data: the yaml data for this schema
|
|
17
21
|
:type yaml_data: dict[str, Any]
|
|
18
22
|
"""
|
|
19
23
|
|
|
20
|
-
def __init__(self,
|
|
21
|
-
super().__init__(yaml_data)
|
|
22
|
-
self.
|
|
23
|
-
self.
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
25
|
+
super().__init__(yaml_data, code_model)
|
|
26
|
+
self.type = yaml_data["type"] # the type discriminator
|
|
27
|
+
self.api_versions: List[str] = yaml_data.get(
|
|
28
|
+
"apiVersions", []
|
|
29
|
+
) # api versions this type is in.
|
|
26
30
|
|
|
27
31
|
@classmethod
|
|
28
32
|
def from_yaml(
|
|
29
|
-
cls,
|
|
30
|
-
) -> "
|
|
31
|
-
return cls(
|
|
33
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
34
|
+
) -> "BaseType":
|
|
35
|
+
return cls(yaml_data=yaml_data, code_model=code_model)
|
|
36
|
+
|
|
37
|
+
def imports( # pylint: disable=no-self-use
|
|
38
|
+
self, **kwargs # pylint: disable=unused-argument
|
|
39
|
+
) -> FileImport:
|
|
40
|
+
return FileImport()
|
|
32
41
|
|
|
33
42
|
@property
|
|
34
|
-
def
|
|
35
|
-
|
|
43
|
+
def xml_metadata(self) -> Dict[str, Any]:
|
|
44
|
+
"""XML metadata for the type, if the type has it."""
|
|
45
|
+
return self.yaml_data.get("xmlMetadata", {})
|
|
36
46
|
|
|
37
47
|
@property
|
|
38
|
-
def
|
|
48
|
+
def is_xml(self) -> bool:
|
|
49
|
+
"""Whether the type is an XML type or not. Most likely not."""
|
|
39
50
|
return bool(self.xml_metadata)
|
|
40
51
|
|
|
52
|
+
@property
|
|
41
53
|
def xml_serialization_ctxt(self) -> Optional[str]:
|
|
42
54
|
"""Return the serialization context in case this schema is used in an operation."""
|
|
43
55
|
attrs_list = []
|
|
@@ -53,12 +65,6 @@ class BaseSchema(BaseModel, ABC):
|
|
|
53
65
|
attrs_list.append(f"'text': True")
|
|
54
66
|
return ", ".join(attrs_list)
|
|
55
67
|
|
|
56
|
-
def imports(self) -> FileImport: # pylint: disable=no-self-use
|
|
57
|
-
return FileImport()
|
|
58
|
-
|
|
59
|
-
def model_file_imports(self) -> FileImport:
|
|
60
|
-
return self.imports()
|
|
61
|
-
|
|
62
68
|
@property
|
|
63
69
|
@abstractmethod
|
|
64
70
|
def serialization_type(self) -> str:
|
|
@@ -75,15 +81,22 @@ class BaseSchema(BaseModel, ABC):
|
|
|
75
81
|
...
|
|
76
82
|
|
|
77
83
|
@property
|
|
84
|
+
def client_default_value(self) -> Any:
|
|
85
|
+
"""Whether there's a client default value for this type"""
|
|
86
|
+
return self.yaml_data.get("clientDefaultValue")
|
|
87
|
+
|
|
78
88
|
@abstractmethod
|
|
79
|
-
def
|
|
80
|
-
"""The
|
|
81
|
-
"""
|
|
89
|
+
def description(self, *, is_operation_file: bool) -> str:
|
|
90
|
+
"""The description"""
|
|
82
91
|
...
|
|
83
92
|
|
|
84
|
-
@property
|
|
85
93
|
@abstractmethod
|
|
86
|
-
def
|
|
94
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
95
|
+
"""The names used in rtype documentation"""
|
|
96
|
+
...
|
|
97
|
+
|
|
98
|
+
@abstractmethod
|
|
99
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
87
100
|
"""The python type used for RST syntax input.
|
|
88
101
|
|
|
89
102
|
Special case for enum, for instance: 'str or ~namespace.EnumName'
|
|
@@ -91,13 +104,22 @@ class BaseSchema(BaseModel, ABC):
|
|
|
91
104
|
...
|
|
92
105
|
|
|
93
106
|
@abstractmethod
|
|
94
|
-
def type_annotation(self,
|
|
107
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
95
108
|
"""The python type used for type annotation
|
|
96
109
|
|
|
97
110
|
Special case for enum, for instance: Union[str, "EnumName"]
|
|
98
111
|
"""
|
|
99
112
|
...
|
|
100
113
|
|
|
114
|
+
@property
|
|
115
|
+
def validation(self) -> Optional[Dict[str, Any]]:
|
|
116
|
+
"""Whether there's any validation constraints on this type.
|
|
117
|
+
|
|
118
|
+
Even though we generate validation maps if there are validation constraints,
|
|
119
|
+
only SDKs with client-side-validate=true (0.001% libraries, if any) actually raise in this case.
|
|
120
|
+
"""
|
|
121
|
+
return None
|
|
122
|
+
|
|
101
123
|
def get_declaration(self, value: Any) -> str: # pylint: disable=no-self-use
|
|
102
124
|
"""Return the current value from YAML as a Python string that represents the constant.
|
|
103
125
|
|
|
@@ -111,28 +133,29 @@ class BaseSchema(BaseModel, ABC):
|
|
|
111
133
|
"""
|
|
112
134
|
return str(value)
|
|
113
135
|
|
|
114
|
-
@
|
|
115
|
-
def
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
136
|
+
@abstractmethod
|
|
137
|
+
def get_json_template_representation(
|
|
138
|
+
self,
|
|
139
|
+
*,
|
|
140
|
+
optional: bool = True,
|
|
141
|
+
client_default_value_declaration: Optional[str] = None,
|
|
142
|
+
description: Optional[str] = None,
|
|
143
|
+
) -> Any:
|
|
144
|
+
"""Template of what this schema would look like as JSON input"""
|
|
145
|
+
...
|
|
121
146
|
|
|
122
|
-
|
|
123
|
-
|
|
147
|
+
def get_polymorphic_subtypes( # pylint: disable=no-self-use
|
|
148
|
+
self, polymorphic_subtypes: List["ModelType"] # pylint: disable=unused-argument
|
|
149
|
+
) -> None:
|
|
124
150
|
return None
|
|
125
151
|
|
|
126
152
|
@property
|
|
127
|
-
def serialization_constraints(self) -> Optional[List[str]]: # pylint: disable=no-self-use
|
|
128
|
-
return None
|
|
129
|
-
|
|
130
153
|
@abstractmethod
|
|
131
|
-
def
|
|
132
|
-
"""Template of what this
|
|
154
|
+
def instance_check_template(self) -> str:
|
|
155
|
+
"""Template of what an instance check of a variable for this type would look like"""
|
|
133
156
|
...
|
|
134
157
|
|
|
135
|
-
@
|
|
136
|
-
def
|
|
137
|
-
"""
|
|
138
|
-
|
|
158
|
+
@property
|
|
159
|
+
def serialization_constraints(self) -> List[str]:
|
|
160
|
+
"""Whether there are any serialization constraints when serializing this type."""
|
|
161
|
+
return []
|