@typespec/http-client-python 0.4.3 → 0.5.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/dist/emitter/emitter.d.ts.map +1 -1
- package/dist/emitter/emitter.js +85 -24
- package/dist/emitter/emitter.js.map +1 -1
- package/dist/emitter/lib.d.ts +1 -0
- package/dist/emitter/lib.d.ts.map +1 -1
- package/dist/emitter/lib.js +1 -0
- package/dist/emitter/lib.js.map +1 -1
- package/dist/emitter/run-python3.d.ts +2 -0
- package/dist/emitter/run-python3.d.ts.map +1 -0
- package/dist/emitter/run-python3.js +19 -0
- package/dist/emitter/run-python3.js.map +1 -0
- package/dist/emitter/system-requirements.d.ts +17 -0
- package/dist/emitter/system-requirements.d.ts.map +1 -0
- package/dist/emitter/system-requirements.js +167 -0
- package/dist/emitter/system-requirements.js.map +1 -0
- package/emitter/src/emitter.ts +88 -23
- package/emitter/src/lib.ts +2 -0
- package/emitter/src/run-python3.ts +20 -0
- package/emitter/src/system-requirements.ts +261 -0
- package/emitter/temp/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/ci/regenerate.ts +16 -4
- package/eng/scripts/setup/__pycache__/venvtools.cpython-38.pyc +0 -0
- package/eng/scripts/setup/build.ts +16 -0
- package/eng/scripts/setup/build_pygen_wheel.py +40 -0
- package/eng/scripts/setup/install.py +9 -3
- package/eng/scripts/setup/install.ts +32 -0
- package/eng/scripts/setup/prepare.py +3 -1
- package/eng/scripts/setup/prepare.ts +11 -0
- package/eng/scripts/setup/run-python3.ts +1 -6
- package/generator/build/lib/pygen/__init__.py +107 -0
- package/generator/build/lib/pygen/_version.py +7 -0
- package/generator/build/lib/pygen/black.py +71 -0
- package/generator/build/lib/pygen/codegen/__init__.py +357 -0
- package/generator/build/lib/pygen/codegen/_utils.py +17 -0
- package/generator/build/lib/pygen/codegen/models/__init__.py +204 -0
- package/generator/build/lib/pygen/codegen/models/base.py +186 -0
- package/generator/build/lib/pygen/codegen/models/base_builder.py +118 -0
- package/generator/build/lib/pygen/codegen/models/client.py +435 -0
- package/generator/build/lib/pygen/codegen/models/code_model.py +237 -0
- package/generator/build/lib/pygen/codegen/models/combined_type.py +149 -0
- package/generator/build/lib/pygen/codegen/models/constant_type.py +129 -0
- package/generator/build/lib/pygen/codegen/models/credential_types.py +214 -0
- package/generator/build/lib/pygen/codegen/models/dictionary_type.py +127 -0
- package/generator/build/lib/pygen/codegen/models/enum_type.py +238 -0
- package/generator/build/lib/pygen/codegen/models/imports.py +291 -0
- package/generator/build/lib/pygen/codegen/models/list_type.py +143 -0
- package/generator/build/lib/pygen/codegen/models/lro_operation.py +142 -0
- package/generator/build/lib/pygen/codegen/models/lro_paging_operation.py +32 -0
- package/generator/build/lib/pygen/codegen/models/model_type.py +357 -0
- package/generator/build/lib/pygen/codegen/models/operation.py +509 -0
- package/generator/build/lib/pygen/codegen/models/operation_group.py +184 -0
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +155 -0
- package/generator/build/lib/pygen/codegen/models/parameter.py +412 -0
- package/generator/build/lib/pygen/codegen/models/parameter_list.py +387 -0
- package/generator/build/lib/pygen/codegen/models/primitive_types.py +659 -0
- package/generator/build/lib/pygen/codegen/models/property.py +170 -0
- package/generator/build/lib/pygen/codegen/models/request_builder.py +189 -0
- package/generator/build/lib/pygen/codegen/models/request_builder_parameter.py +115 -0
- package/generator/build/lib/pygen/codegen/models/response.py +348 -0
- package/generator/build/lib/pygen/codegen/models/utils.py +21 -0
- package/generator/build/lib/pygen/codegen/serializers/__init__.py +574 -0
- package/generator/build/lib/pygen/codegen/serializers/base_serializer.py +21 -0
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +1533 -0
- package/generator/build/lib/pygen/codegen/serializers/client_serializer.py +294 -0
- package/generator/build/lib/pygen/codegen/serializers/enum_serializer.py +15 -0
- package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +213 -0
- package/generator/build/lib/pygen/codegen/serializers/import_serializer.py +126 -0
- package/generator/build/lib/pygen/codegen/serializers/metadata_serializer.py +198 -0
- package/generator/build/lib/pygen/codegen/serializers/model_init_serializer.py +33 -0
- package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +335 -0
- package/generator/build/lib/pygen/codegen/serializers/operation_groups_serializer.py +89 -0
- package/generator/build/lib/pygen/codegen/serializers/operations_init_serializer.py +44 -0
- package/generator/build/lib/pygen/codegen/serializers/parameter_serializer.py +221 -0
- package/generator/build/lib/pygen/codegen/serializers/patch_serializer.py +19 -0
- package/generator/build/lib/pygen/codegen/serializers/request_builders_serializer.py +52 -0
- package/generator/build/lib/pygen/codegen/serializers/sample_serializer.py +168 -0
- package/generator/build/lib/pygen/codegen/serializers/test_serializer.py +292 -0
- package/generator/build/lib/pygen/codegen/serializers/types_serializer.py +31 -0
- package/generator/build/lib/pygen/codegen/serializers/utils.py +68 -0
- package/generator/build/lib/pygen/codegen/templates/client.py.jinja2 +37 -0
- package/generator/build/lib/pygen/codegen/templates/client_container.py.jinja2 +12 -0
- package/generator/build/lib/pygen/codegen/templates/config.py.jinja2 +73 -0
- package/generator/build/lib/pygen/codegen/templates/config_container.py.jinja2 +16 -0
- package/generator/build/lib/pygen/codegen/templates/conftest.py.jinja2 +28 -0
- package/generator/build/lib/pygen/codegen/templates/enum.py.jinja2 +13 -0
- package/generator/build/lib/pygen/codegen/templates/enum_container.py.jinja2 +10 -0
- package/generator/build/lib/pygen/codegen/templates/init.py.jinja2 +24 -0
- package/generator/build/lib/pygen/codegen/templates/keywords.jinja2 +27 -0
- package/generator/build/lib/pygen/codegen/templates/lro_operation.py.jinja2 +16 -0
- package/generator/build/lib/pygen/codegen/templates/lro_paging_operation.py.jinja2 +18 -0
- package/generator/build/lib/pygen/codegen/templates/macros.jinja2 +12 -0
- package/generator/build/lib/pygen/codegen/templates/metadata.json.jinja2 +167 -0
- package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +1174 -0
- package/generator/build/lib/pygen/codegen/templates/model_container.py.jinja2 +15 -0
- package/generator/build/lib/pygen/codegen/templates/model_dpg.py.jinja2 +97 -0
- package/generator/build/lib/pygen/codegen/templates/model_init.py.jinja2 +33 -0
- package/generator/build/lib/pygen/codegen/templates/model_msrest.py.jinja2 +92 -0
- package/generator/build/lib/pygen/codegen/templates/operation.py.jinja2 +21 -0
- package/generator/build/lib/pygen/codegen/templates/operation_group.py.jinja2 +75 -0
- package/generator/build/lib/pygen/codegen/templates/operation_groups_container.py.jinja2 +19 -0
- package/generator/build/lib/pygen/codegen/templates/operation_tools.jinja2 +81 -0
- package/generator/build/lib/pygen/codegen/templates/operations_folder_init.py.jinja2 +17 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/CHANGELOG.md.jinja2 +6 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/LICENSE.jinja2 +21 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 +8 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/README.md.jinja2 +107 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +9 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +108 -0
- package/generator/build/lib/pygen/codegen/templates/paging_operation.py.jinja2 +21 -0
- package/generator/build/lib/pygen/codegen/templates/patch.py.jinja2 +19 -0
- package/generator/build/lib/pygen/codegen/templates/pkgutil_init.py.jinja2 +1 -0
- package/generator/build/lib/pygen/codegen/templates/request_builder.py.jinja2 +28 -0
- package/generator/build/lib/pygen/codegen/templates/request_builders.py.jinja2 +10 -0
- package/generator/build/lib/pygen/codegen/templates/rest_init.py.jinja2 +12 -0
- package/generator/build/lib/pygen/codegen/templates/sample.py.jinja2 +44 -0
- package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +2117 -0
- package/generator/build/lib/pygen/codegen/templates/test.py.jinja2 +50 -0
- package/generator/build/lib/pygen/codegen/templates/testpreparer.py.jinja2 +26 -0
- package/generator/build/lib/pygen/codegen/templates/types.py.jinja2 +7 -0
- package/generator/build/lib/pygen/codegen/templates/validation.py.jinja2 +38 -0
- package/generator/build/lib/pygen/codegen/templates/vendor.py.jinja2 +96 -0
- package/generator/build/lib/pygen/codegen/templates/version.py.jinja2 +4 -0
- package/generator/build/lib/pygen/m2r.py +65 -0
- package/generator/build/lib/pygen/preprocess/__init__.py +515 -0
- package/generator/build/lib/pygen/preprocess/helpers.py +27 -0
- package/generator/build/lib/pygen/preprocess/python_mappings.py +226 -0
- package/generator/build/lib/pygen/utils.py +163 -0
- package/generator/component-detection-pip-report.json +134 -0
- package/generator/dev_requirements.txt +0 -1
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/m2r.py +1 -1
- package/generator/pygen.egg-info/PKG-INFO +7 -4
- package/generator/pygen.egg-info/requires.txt +7 -4
- package/generator/requirements.txt +5 -10
- package/generator/setup.py +7 -4
- package/generator/test/azure/requirements.txt +2 -0
- package/generator/test/generic_mock_api_tests/unittests/test_m2r.py +10 -0
- package/generator/test/unbranded/requirements.txt +2 -0
- package/package.json +6 -5
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
import logging
|
|
7
|
+
from typing import Any, Dict, Union, Optional
|
|
8
|
+
from .base import BaseModel
|
|
9
|
+
from .base_builder import BaseBuilder, ParameterListType
|
|
10
|
+
from .code_model import CodeModel
|
|
11
|
+
from .client import Client
|
|
12
|
+
from .model_type import ModelType, JSONModelType, DPGModelType, MsrestModelType
|
|
13
|
+
from .dictionary_type import DictionaryType
|
|
14
|
+
from .list_type import ListType
|
|
15
|
+
from .combined_type import CombinedType
|
|
16
|
+
from .primitive_types import (
|
|
17
|
+
ByteArraySchema,
|
|
18
|
+
DateType,
|
|
19
|
+
DatetimeType,
|
|
20
|
+
DurationType,
|
|
21
|
+
IntegerType,
|
|
22
|
+
FloatType,
|
|
23
|
+
StringType,
|
|
24
|
+
TimeType,
|
|
25
|
+
AnyType,
|
|
26
|
+
PrimitiveType,
|
|
27
|
+
BinaryType,
|
|
28
|
+
BooleanType,
|
|
29
|
+
AnyObjectType,
|
|
30
|
+
UnixTimeType,
|
|
31
|
+
SdkCoreType,
|
|
32
|
+
DecimalType,
|
|
33
|
+
MultiPartFileType,
|
|
34
|
+
)
|
|
35
|
+
from .enum_type import EnumType, EnumValue
|
|
36
|
+
from .base import BaseType
|
|
37
|
+
from .constant_type import ConstantType
|
|
38
|
+
from .imports import FileImport, ImportType, TypingSection
|
|
39
|
+
from .lro_operation import LROOperation
|
|
40
|
+
from .paging_operation import PagingOperation
|
|
41
|
+
from .parameter import (
|
|
42
|
+
Parameter,
|
|
43
|
+
ParameterMethodLocation,
|
|
44
|
+
ParameterLocation,
|
|
45
|
+
BodyParameter,
|
|
46
|
+
ParameterDelimeter,
|
|
47
|
+
ClientParameter,
|
|
48
|
+
ConfigParameter,
|
|
49
|
+
)
|
|
50
|
+
from .operation import Operation
|
|
51
|
+
from .property import Property
|
|
52
|
+
from .operation_group import OperationGroup
|
|
53
|
+
from .response import Response
|
|
54
|
+
from .parameter_list import (
|
|
55
|
+
ParameterList,
|
|
56
|
+
ClientGlobalParameterList,
|
|
57
|
+
ConfigGlobalParameterList,
|
|
58
|
+
)
|
|
59
|
+
from .request_builder import (
|
|
60
|
+
RequestBuilder,
|
|
61
|
+
OverloadedRequestBuilder,
|
|
62
|
+
RequestBuilderBase,
|
|
63
|
+
)
|
|
64
|
+
from .lro_paging_operation import LROPagingOperation
|
|
65
|
+
from .request_builder_parameter import (
|
|
66
|
+
RequestBuilderParameter,
|
|
67
|
+
RequestBuilderBodyParameter,
|
|
68
|
+
)
|
|
69
|
+
from .credential_types import (
|
|
70
|
+
TokenCredentialType,
|
|
71
|
+
KeyCredentialType,
|
|
72
|
+
ARMChallengeAuthenticationPolicyType,
|
|
73
|
+
BearerTokenCredentialPolicyType,
|
|
74
|
+
KeyCredentialPolicyType,
|
|
75
|
+
CredentialType,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
__all__ = [
|
|
79
|
+
"KeyCredentialPolicyType",
|
|
80
|
+
"AnyType",
|
|
81
|
+
"BaseModel",
|
|
82
|
+
"BaseType",
|
|
83
|
+
"CodeModel",
|
|
84
|
+
"Client",
|
|
85
|
+
"ConstantType",
|
|
86
|
+
"ModelType",
|
|
87
|
+
"DictionaryType",
|
|
88
|
+
"ListType",
|
|
89
|
+
"EnumType",
|
|
90
|
+
"EnumValue",
|
|
91
|
+
"FileImport",
|
|
92
|
+
"ImportType",
|
|
93
|
+
"TypingSection",
|
|
94
|
+
"PrimitiveType",
|
|
95
|
+
"LROOperation",
|
|
96
|
+
"Operation",
|
|
97
|
+
"PagingOperation",
|
|
98
|
+
"Parameter",
|
|
99
|
+
"ParameterList",
|
|
100
|
+
"OperationGroup",
|
|
101
|
+
"Property",
|
|
102
|
+
"RequestBuilder",
|
|
103
|
+
"Response",
|
|
104
|
+
"TokenCredentialType",
|
|
105
|
+
"LROPagingOperation",
|
|
106
|
+
"BaseBuilder",
|
|
107
|
+
"RequestBuilderParameter",
|
|
108
|
+
"BinaryType",
|
|
109
|
+
"ClientGlobalParameterList",
|
|
110
|
+
"ConfigGlobalParameterList",
|
|
111
|
+
"ParameterMethodLocation",
|
|
112
|
+
"ParameterLocation",
|
|
113
|
+
"OverloadedRequestBuilder",
|
|
114
|
+
"RequestBuilderBase",
|
|
115
|
+
"BodyParameter",
|
|
116
|
+
"RequestBuilderBodyParameter",
|
|
117
|
+
"ParameterDelimeter",
|
|
118
|
+
"CredentialType",
|
|
119
|
+
"ClientParameter",
|
|
120
|
+
"ConfigParameter",
|
|
121
|
+
"ParameterListType",
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
TYPE_TO_OBJECT = {
|
|
125
|
+
"integer": IntegerType,
|
|
126
|
+
"float": FloatType,
|
|
127
|
+
"decimal": DecimalType,
|
|
128
|
+
"string": StringType,
|
|
129
|
+
"list": ListType,
|
|
130
|
+
"dict": DictionaryType,
|
|
131
|
+
"constant": ConstantType,
|
|
132
|
+
"enum": EnumType,
|
|
133
|
+
"enumvalue": EnumValue,
|
|
134
|
+
"binary": BinaryType,
|
|
135
|
+
"any": AnyType,
|
|
136
|
+
"utcDateTime": DatetimeType,
|
|
137
|
+
"offsetDateTime": DatetimeType,
|
|
138
|
+
"plainTime": TimeType,
|
|
139
|
+
"duration": DurationType,
|
|
140
|
+
"plainDate": DateType,
|
|
141
|
+
"bytes": ByteArraySchema,
|
|
142
|
+
"boolean": BooleanType,
|
|
143
|
+
"combined": CombinedType,
|
|
144
|
+
"OAuth2": TokenCredentialType,
|
|
145
|
+
"Key": KeyCredentialType,
|
|
146
|
+
"ARMChallengeAuthenticationPolicy": ARMChallengeAuthenticationPolicyType,
|
|
147
|
+
"BearerTokenCredentialPolicy": BearerTokenCredentialPolicyType,
|
|
148
|
+
"KeyCredentialPolicy": KeyCredentialPolicyType,
|
|
149
|
+
"any-object": AnyObjectType,
|
|
150
|
+
"unixtime": UnixTimeType,
|
|
151
|
+
"credential": StringType,
|
|
152
|
+
"sdkcore": SdkCoreType,
|
|
153
|
+
"multipartfile": MultiPartFileType,
|
|
154
|
+
}
|
|
155
|
+
_LOGGER = logging.getLogger(__name__)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def build_type(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseType:
|
|
159
|
+
yaml_id = id(yaml_data)
|
|
160
|
+
try:
|
|
161
|
+
return code_model.lookup_type(yaml_id)
|
|
162
|
+
except KeyError:
|
|
163
|
+
# Not created yet, let's create it and add it to the index
|
|
164
|
+
pass
|
|
165
|
+
response: Optional[BaseType] = None
|
|
166
|
+
if yaml_data["type"] == "model":
|
|
167
|
+
# need to special case model to avoid recursion
|
|
168
|
+
if yaml_data["base"] == "json" or not code_model.options["models_mode"]:
|
|
169
|
+
model_type = JSONModelType
|
|
170
|
+
elif yaml_data["base"] == "dpg":
|
|
171
|
+
model_type = DPGModelType # type: ignore
|
|
172
|
+
else:
|
|
173
|
+
model_type = MsrestModelType # type: ignore
|
|
174
|
+
response = model_type(yaml_data, code_model)
|
|
175
|
+
code_model.types_map[yaml_id] = response
|
|
176
|
+
response.fill_instance_from_yaml(yaml_data, code_model)
|
|
177
|
+
elif yaml_data["type"] == "enum":
|
|
178
|
+
# avoid recursion because we add the parent enum type to the enum value
|
|
179
|
+
response = EnumType(
|
|
180
|
+
yaml_data,
|
|
181
|
+
code_model,
|
|
182
|
+
values=[],
|
|
183
|
+
value_type=build_type(yaml_data["valueType"], code_model),
|
|
184
|
+
)
|
|
185
|
+
code_model.types_map[yaml_id] = response
|
|
186
|
+
response.fill_instance_from_yaml(yaml_data, code_model)
|
|
187
|
+
else:
|
|
188
|
+
object_type = yaml_data.get("type")
|
|
189
|
+
if object_type not in TYPE_TO_OBJECT:
|
|
190
|
+
_LOGGER.warning(
|
|
191
|
+
'Unrecognized definition type "%s" is found, falling back it as "string"! ',
|
|
192
|
+
yaml_data["type"],
|
|
193
|
+
)
|
|
194
|
+
object_type = "string"
|
|
195
|
+
response = TYPE_TO_OBJECT[object_type].from_yaml(yaml_data, code_model) # type: ignore
|
|
196
|
+
if response is None:
|
|
197
|
+
raise ValueError("response can not be None")
|
|
198
|
+
code_model.types_map[yaml_id] = response
|
|
199
|
+
return response
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
RequestBuilderType = Union[RequestBuilder, OverloadedRequestBuilder]
|
|
203
|
+
ParameterType = Union[Parameter, RequestBuilderParameter, ClientParameter, ConfigParameter]
|
|
204
|
+
OperationType = Union[Operation, LROOperation, PagingOperation, LROPagingOperation]
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
from typing import Any, Dict, TYPE_CHECKING, List, Optional
|
|
7
|
+
from abc import ABC, abstractmethod
|
|
8
|
+
from .imports import FileImport
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from .code_model import CodeModel
|
|
13
|
+
from .model_type import ModelType
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BaseModel:
|
|
17
|
+
"""This is the base class for model representations that are based on some YAML data.
|
|
18
|
+
|
|
19
|
+
:param yaml_data: the yaml data for this schema
|
|
20
|
+
:type yaml_data: dict[str, Any]
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
24
|
+
self.yaml_data = yaml_data
|
|
25
|
+
self.code_model = code_model
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def id(self) -> int:
|
|
29
|
+
return id(self.yaml_data)
|
|
30
|
+
|
|
31
|
+
def __repr__(self):
|
|
32
|
+
return f"<{self.__class__.__name__}>"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
36
|
+
"""This is the base class for all types.
|
|
37
|
+
|
|
38
|
+
:param yaml_data: the yaml data for this schema
|
|
39
|
+
:type yaml_data: dict[str, Any]
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
43
|
+
super().__init__(yaml_data, code_model)
|
|
44
|
+
self.type = yaml_data["type"] # the type discriminator
|
|
45
|
+
self.api_versions: List[str] = yaml_data.get("apiVersions", []) # api versions this type is in.
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "BaseType":
|
|
49
|
+
return cls(yaml_data=yaml_data, code_model=code_model)
|
|
50
|
+
|
|
51
|
+
def imports(self, **kwargs) -> FileImport: # pylint: disable=unused-argument
|
|
52
|
+
return FileImport(self.code_model)
|
|
53
|
+
|
|
54
|
+
def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
|
|
55
|
+
return self.imports(**kwargs)
|
|
56
|
+
|
|
57
|
+
def imports_for_sample(self) -> FileImport:
|
|
58
|
+
return FileImport(self.code_model)
|
|
59
|
+
|
|
60
|
+
@staticmethod
|
|
61
|
+
def serialize_sample_value(value: Any) -> str:
|
|
62
|
+
return repr(value)
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def xml_metadata(self) -> Dict[str, Any]:
|
|
66
|
+
"""XML metadata for the type, if the type has it."""
|
|
67
|
+
return self.yaml_data.get("xmlMetadata", {})
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def is_xml(self) -> bool:
|
|
71
|
+
"""Whether the type is an XML type or not. Most likely not."""
|
|
72
|
+
return bool(self.xml_metadata)
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def xml_serialization_ctxt(self) -> Optional[str]:
|
|
76
|
+
"""Return the serialization context in case this schema is used in an operation."""
|
|
77
|
+
attrs_list = []
|
|
78
|
+
if self.xml_metadata.get("name"):
|
|
79
|
+
attrs_list.append(f"'name': '{self.xml_metadata['name']}'")
|
|
80
|
+
if self.xml_metadata.get("attribute", False):
|
|
81
|
+
attrs_list.append("'attr': True")
|
|
82
|
+
if self.xml_metadata.get("prefix", False):
|
|
83
|
+
attrs_list.append(f"'prefix': '{self.xml_metadata['prefix']}'")
|
|
84
|
+
if self.xml_metadata.get("namespace", False):
|
|
85
|
+
attrs_list.append(f"'ns': '{self.xml_metadata['namespace']}'")
|
|
86
|
+
if self.xml_metadata.get("text"):
|
|
87
|
+
attrs_list.append("'text': True")
|
|
88
|
+
return ", ".join(attrs_list)
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def serialization_type(self) -> str:
|
|
92
|
+
"""The tag recognized by 'msrest' as a serialization/deserialization.
|
|
93
|
+
|
|
94
|
+
'str', 'int', 'float', 'bool' or
|
|
95
|
+
https://github.com/Azure/msrest-for-python/blob/b505e3627b547bd8fdc38327e86c70bdb16df061/msrest/serialization.py#L407-L416
|
|
96
|
+
|
|
97
|
+
or the object schema name (e.g. DotSalmon).
|
|
98
|
+
|
|
99
|
+
If list: '[str]'
|
|
100
|
+
If dict: '{str}'
|
|
101
|
+
"""
|
|
102
|
+
raise NotImplementedError()
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def msrest_deserialization_key(self) -> str:
|
|
106
|
+
return self.serialization_type
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def client_default_value(self) -> Any:
|
|
110
|
+
"""Whether there's a client default value for this type"""
|
|
111
|
+
return self.yaml_data.get("clientDefaultValue")
|
|
112
|
+
|
|
113
|
+
@abstractmethod
|
|
114
|
+
def description(self, *, is_operation_file: bool) -> str:
|
|
115
|
+
"""The description"""
|
|
116
|
+
|
|
117
|
+
@abstractmethod
|
|
118
|
+
def docstring_text(self, **kwargs: Any) -> str:
|
|
119
|
+
"""The names used in rtype documentation"""
|
|
120
|
+
|
|
121
|
+
@abstractmethod
|
|
122
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
123
|
+
"""The python type used for RST syntax input.
|
|
124
|
+
|
|
125
|
+
Special case for enum, for instance: 'str or ~namespace.EnumName'
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
@abstractmethod
|
|
129
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
130
|
+
"""The python type used for type annotation
|
|
131
|
+
|
|
132
|
+
Special case for enum, for instance: Union[str, "EnumName"]
|
|
133
|
+
"""
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def validation(self) -> Optional[Dict[str, Any]]:
|
|
137
|
+
"""Whether there's any validation constraints on this type.
|
|
138
|
+
|
|
139
|
+
Even though we generate validation maps if there are validation constraints,
|
|
140
|
+
only SDKs with client-side-validate=true (0.001% libraries, if any) actually raise in this case.
|
|
141
|
+
"""
|
|
142
|
+
return None
|
|
143
|
+
|
|
144
|
+
def get_declaration(self, value: Any) -> str:
|
|
145
|
+
"""Return the current value from YAML as a Python string that represents the constant.
|
|
146
|
+
|
|
147
|
+
Example, if schema is "bytearray" and value is "foo",
|
|
148
|
+
should return bytearray("foo", encoding="utf-8")
|
|
149
|
+
as a string.
|
|
150
|
+
|
|
151
|
+
This is important for constant serialization.
|
|
152
|
+
|
|
153
|
+
By default, return value, since it works sometimes (integer)
|
|
154
|
+
"""
|
|
155
|
+
return str(value)
|
|
156
|
+
|
|
157
|
+
@abstractmethod
|
|
158
|
+
def get_json_template_representation(
|
|
159
|
+
self,
|
|
160
|
+
*,
|
|
161
|
+
client_default_value_declaration: Optional[str] = None,
|
|
162
|
+
) -> Any:
|
|
163
|
+
"""Template of what this schema would look like as JSON input"""
|
|
164
|
+
|
|
165
|
+
def get_polymorphic_subtypes(
|
|
166
|
+
self, polymorphic_subtypes: List["ModelType"] # pylint: disable=unused-argument
|
|
167
|
+
) -> None:
|
|
168
|
+
return None
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
@abstractmethod
|
|
172
|
+
def instance_check_template(self) -> str:
|
|
173
|
+
"""Template of what an instance check of a variable for this type would look like"""
|
|
174
|
+
|
|
175
|
+
@property
|
|
176
|
+
def serialization_constraints(self) -> List[str]:
|
|
177
|
+
"""Whether there are any serialization constraints when serializing this type."""
|
|
178
|
+
return []
|
|
179
|
+
|
|
180
|
+
@property
|
|
181
|
+
def type_description(self) -> str:
|
|
182
|
+
return self.type_annotation()
|
|
183
|
+
|
|
184
|
+
@property
|
|
185
|
+
def is_form_data(self) -> bool:
|
|
186
|
+
return False
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
import logging
|
|
7
|
+
from typing import (
|
|
8
|
+
List,
|
|
9
|
+
Dict,
|
|
10
|
+
Any,
|
|
11
|
+
Generic,
|
|
12
|
+
TypeVar,
|
|
13
|
+
Optional,
|
|
14
|
+
Union,
|
|
15
|
+
TYPE_CHECKING,
|
|
16
|
+
cast,
|
|
17
|
+
)
|
|
18
|
+
from abc import abstractmethod
|
|
19
|
+
|
|
20
|
+
from .base import BaseModel
|
|
21
|
+
from .parameter_list import (
|
|
22
|
+
ParameterList,
|
|
23
|
+
RequestBuilderParameterList,
|
|
24
|
+
OverloadedRequestBuilderParameterList,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
ParameterListType = TypeVar(
|
|
28
|
+
"ParameterListType",
|
|
29
|
+
bound=Union[
|
|
30
|
+
ParameterList,
|
|
31
|
+
RequestBuilderParameterList,
|
|
32
|
+
OverloadedRequestBuilderParameterList,
|
|
33
|
+
],
|
|
34
|
+
)
|
|
35
|
+
if TYPE_CHECKING:
|
|
36
|
+
from .code_model import CodeModel
|
|
37
|
+
from .client import Client
|
|
38
|
+
from .operation import Operation
|
|
39
|
+
from .request_builder import RequestBuilder
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
OverloadListType = TypeVar("OverloadListType", bound=Union[List["Operation"], List["RequestBuilder"]])
|
|
43
|
+
|
|
44
|
+
_LOGGER = logging.getLogger(__name__)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class BaseBuilder(
|
|
48
|
+
Generic[ParameterListType, OverloadListType], BaseModel
|
|
49
|
+
): # pylint: disable=too-many-instance-attributes
|
|
50
|
+
"""Base class for Operations and Request Builders"""
|
|
51
|
+
|
|
52
|
+
def __init__(
|
|
53
|
+
self,
|
|
54
|
+
yaml_data: Dict[str, Any],
|
|
55
|
+
code_model: "CodeModel",
|
|
56
|
+
client: "Client",
|
|
57
|
+
name: str,
|
|
58
|
+
parameters: ParameterListType,
|
|
59
|
+
*,
|
|
60
|
+
overloads: Optional[OverloadListType] = None,
|
|
61
|
+
) -> None:
|
|
62
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
63
|
+
self.client = client
|
|
64
|
+
self.name = name
|
|
65
|
+
self._description: str = yaml_data.get("description", "")
|
|
66
|
+
self.parameters = parameters
|
|
67
|
+
self.overloads = overloads or cast(OverloadListType, [])
|
|
68
|
+
self._summary: str = yaml_data.get("summary", "")
|
|
69
|
+
self.want_tracing: bool = yaml_data.get("wantTracing", True)
|
|
70
|
+
self.group_name: str = yaml_data["groupName"] # either operationGroup or client I am on
|
|
71
|
+
self.is_overload: bool = yaml_data["isOverload"]
|
|
72
|
+
self.api_versions: List[str] = yaml_data["apiVersions"]
|
|
73
|
+
self.added_on: Optional[str] = yaml_data.get("addedOn")
|
|
74
|
+
self.external_docs: Optional[Dict[str, Any]] = yaml_data.get("externalDocs")
|
|
75
|
+
|
|
76
|
+
if code_model.options["version_tolerant"] and yaml_data.get("abstract"):
|
|
77
|
+
_LOGGER.warning(
|
|
78
|
+
'Not going to generate operation "%s" because we are unable to generate this '
|
|
79
|
+
"type of operation right now. "
|
|
80
|
+
'Please write your own custom operation in the "_patch.py" file '
|
|
81
|
+
"following https://aka.ms/azsdk/python/dpcodegen/python/customize",
|
|
82
|
+
name,
|
|
83
|
+
)
|
|
84
|
+
self.abstract = True
|
|
85
|
+
else:
|
|
86
|
+
self.abstract = False
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def summary(self) -> Optional[str]:
|
|
90
|
+
if self.abstract:
|
|
91
|
+
return None
|
|
92
|
+
return self._summary
|
|
93
|
+
|
|
94
|
+
def pylint_disable(self, async_mode: bool) -> str: # pylint: disable=unused-argument
|
|
95
|
+
return ""
|
|
96
|
+
|
|
97
|
+
@abstractmethod
|
|
98
|
+
def response_type_annotation(self, **kwargs) -> str: ...
|
|
99
|
+
|
|
100
|
+
@abstractmethod
|
|
101
|
+
def response_docstring_text(self, **kwargs) -> str: ...
|
|
102
|
+
|
|
103
|
+
@abstractmethod
|
|
104
|
+
def response_docstring_type(self, **kwargs) -> str: ...
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def description(self) -> str:
|
|
108
|
+
if self.abstract:
|
|
109
|
+
return (
|
|
110
|
+
f'You need to write a custom operation for "{self.name}". Please refer to '
|
|
111
|
+
"https://aka.ms/azsdk/python/dpcodegen/python/customize to learn how to customize."
|
|
112
|
+
)
|
|
113
|
+
return self._description or self.name
|
|
114
|
+
|
|
115
|
+
def method_signature(self, async_mode: bool) -> List[str]:
|
|
116
|
+
if self.abstract:
|
|
117
|
+
return ["*args,", "**kwargs"]
|
|
118
|
+
return self.parameters.method_signature(async_mode)
|