@azure-tools/typespec-python 0.29.0 → 0.31.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/scripts/eng/format.d.ts +2 -0
- package/dist/scripts/eng/format.d.ts.map +1 -0
- package/dist/scripts/eng/format.js +4 -0
- package/dist/scripts/eng/format.js.map +1 -0
- package/dist/scripts/eng/lint.d.ts +5 -0
- package/dist/scripts/eng/lint.d.ts.map +1 -0
- package/dist/scripts/eng/lint.js +66 -0
- package/dist/scripts/eng/lint.js.map +1 -0
- package/dist/scripts/{regenerate.d.ts.map → eng/regenerate.d.ts.map} +1 -1
- package/dist/scripts/{regenerate.js → eng/regenerate.js} +27 -29
- package/dist/scripts/eng/regenerate.js.map +1 -0
- package/dist/scripts/{run-tests.d.ts.map → eng/run-tests.d.ts.map} +1 -1
- package/dist/scripts/eng/run-tests.js +80 -0
- package/dist/scripts/eng/run-tests.js.map +1 -0
- package/dist/scripts/eng/utils.d.ts +3 -0
- package/dist/scripts/eng/utils.d.ts.map +1 -0
- package/dist/scripts/eng/utils.js +39 -0
- package/dist/scripts/eng/utils.js.map +1 -0
- package/dist/scripts/system-requirements.d.ts.map +1 -1
- package/dist/scripts/system-requirements.js.map +1 -1
- package/dist/src/code-model.d.ts.map +1 -1
- package/dist/src/code-model.js +4 -1
- package/dist/src/code-model.js.map +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +17 -4
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/external-process.d.ts +0 -1
- package/dist/src/external-process.d.ts.map +1 -1
- package/dist/src/http.js +14 -8
- package/dist/src/http.js.map +1 -1
- package/dist/src/lib.d.ts +1 -0
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +1 -0
- package/dist/src/lib.js.map +1 -1
- package/dist/src/types.d.ts +1 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +82 -9
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils.d.ts +2 -2
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +65 -10
- package/dist/src/utils.js.map +1 -1
- package/generator/pygen/black.py +2 -3
- package/generator/pygen/codegen/models/combined_type.py +1 -1
- package/generator/pygen/codegen/models/credential_types.py +7 -14
- package/generator/pygen/codegen/models/enum_type.py +1 -1
- package/generator/pygen/codegen/models/lro_operation.py +0 -1
- package/generator/pygen/codegen/models/lro_paging_operation.py +1 -1
- package/generator/pygen/codegen/models/model_type.py +5 -7
- package/generator/pygen/codegen/models/operation.py +13 -2
- package/generator/pygen/codegen/models/paging_operation.py +0 -1
- package/generator/pygen/codegen/models/parameter.py +5 -1
- package/generator/pygen/codegen/models/parameter_list.py +2 -5
- package/generator/pygen/codegen/models/primitive_types.py +11 -4
- package/generator/pygen/codegen/models/property.py +5 -1
- package/generator/pygen/codegen/serializers/__init__.py +1 -1
- package/generator/pygen/codegen/serializers/builder_serializer.py +22 -20
- package/generator/pygen/codegen/serializers/general_serializer.py +2 -1
- package/generator/pygen/codegen/serializers/model_serializer.py +3 -0
- package/generator/pygen/codegen/serializers/sample_serializer.py +1 -3
- package/generator/pygen/codegen/serializers/test_serializer.py +6 -0
- package/generator/pygen/codegen/templates/model_base.py.jinja2 +319 -67
- package/generator/pygen/codegen/templates/model_dpg.py.jinja2 +5 -0
- package/generator/pygen/codegen/templates/serialization.py.jinja2 +271 -162
- package/generator/pygen/codegen/templates/test.py.jinja2 +2 -2
- package/generator/pygen/m2r.py +1 -1
- package/generator/pygen/postprocess/__init__.py +2 -2
- package/generator/pygen/postprocess/venvtools.py +1 -3
- package/generator/pygen/preprocess/__init__.py +1 -1
- package/generator/pygen/utils.py +10 -3
- package/generator/setup.py +1 -1
- package/package.json +13 -10
- package/scripts/__pycache__/venvtools.cpython-310.pyc +0 -0
- package/scripts/eng/format.ts +5 -0
- package/scripts/eng/lint.ts +75 -0
- package/scripts/eng/mypy.ini +38 -0
- package/scripts/eng/pylintrc +58 -0
- package/scripts/eng/pyrightconfig.json +6 -0
- package/scripts/{regenerate.ts → eng/regenerate.ts} +40 -33
- package/scripts/eng/run-tests.ts +90 -0
- package/scripts/eng/utils.ts +38 -0
- package/scripts/run_tsp.py +7 -5
- package/dist/scripts/regenerate.js.map +0 -1
- package/dist/scripts/run-tests.js +0 -50
- package/dist/scripts/run-tests.js.map +0 -1
- package/scripts/run-tests.ts +0 -57
- /package/dist/scripts/{regenerate.d.ts → eng/regenerate.d.ts} +0 -0
- /package/dist/scripts/{run-tests.d.ts → eng/run-tests.d.ts} +0 -0
|
@@ -106,7 +106,7 @@ CredentialPolicyType = TypeVar(
|
|
|
106
106
|
)
|
|
107
107
|
|
|
108
108
|
|
|
109
|
-
class CredentialType(Generic[CredentialPolicyType], BaseType):
|
|
109
|
+
class CredentialType(Generic[CredentialPolicyType], BaseType):
|
|
110
110
|
"""Store info about the type of the credential. Can be either an KeyCredential or a TokenCredential"""
|
|
111
111
|
|
|
112
112
|
def __init__(
|
|
@@ -118,7 +118,7 @@ class CredentialType(Generic[CredentialPolicyType], BaseType): # pylint:disable
|
|
|
118
118
|
super().__init__(yaml_data, code_model)
|
|
119
119
|
self.policy = policy
|
|
120
120
|
|
|
121
|
-
def description(self, *, is_operation_file: bool) -> str:
|
|
121
|
+
def description(self, *, is_operation_file: bool) -> str:
|
|
122
122
|
return ""
|
|
123
123
|
|
|
124
124
|
def get_json_template_representation(
|
|
@@ -146,11 +146,7 @@ class CredentialType(Generic[CredentialPolicyType], BaseType): # pylint:disable
|
|
|
146
146
|
)
|
|
147
147
|
|
|
148
148
|
|
|
149
|
-
class TokenCredentialType(
|
|
150
|
-
CredentialType[ # pylint: disable=unsubscriptable-object
|
|
151
|
-
Union[BearerTokenCredentialPolicyType, ARMChallengeAuthenticationPolicyType]
|
|
152
|
-
]
|
|
153
|
-
):
|
|
149
|
+
class TokenCredentialType(CredentialType[Union[BearerTokenCredentialPolicyType, ARMChallengeAuthenticationPolicyType]]):
|
|
154
150
|
"""Type of a token credential. Used by BearerAuth and ARMChallenge policies"""
|
|
155
151
|
|
|
156
152
|
def type_annotation(self, **kwargs: Any) -> str:
|
|
@@ -194,23 +190,20 @@ class TokenCredentialType(
|
|
|
194
190
|
return "hasattr({}, 'get_token')"
|
|
195
191
|
|
|
196
192
|
|
|
197
|
-
class KeyCredentialType(
|
|
198
|
-
# pylint: disable=unsubscriptable-object
|
|
199
|
-
CredentialType[KeyCredentialPolicyType]
|
|
200
|
-
):
|
|
193
|
+
class KeyCredentialType(CredentialType[KeyCredentialPolicyType]):
|
|
201
194
|
"""Type for an KeyCredential"""
|
|
202
195
|
|
|
203
|
-
def docstring_type(self, **kwargs: Any) -> str:
|
|
196
|
+
def docstring_type(self, **kwargs: Any) -> str:
|
|
204
197
|
return f"~{self.code_model.core_library}.credentials.{self.policy.credential_name}"
|
|
205
198
|
|
|
206
|
-
def type_annotation(self, **kwargs: Any) -> str:
|
|
199
|
+
def type_annotation(self, **kwargs: Any) -> str:
|
|
207
200
|
return self.policy.credential_name
|
|
208
201
|
|
|
209
202
|
@property
|
|
210
203
|
def instance_check_template(self) -> str:
|
|
211
204
|
return "isinstance({}, " + f"{self.policy.credential_name})"
|
|
212
205
|
|
|
213
|
-
def imports(self, **kwargs: Any) -> FileImport:
|
|
206
|
+
def imports(self, **kwargs: Any) -> FileImport:
|
|
214
207
|
file_import = super().imports(**kwargs)
|
|
215
208
|
file_import.add_submodule_import(
|
|
216
209
|
"credentials",
|
|
@@ -137,7 +137,7 @@ class EnumType(BaseType):
|
|
|
137
137
|
"""
|
|
138
138
|
return self.value_type.serialization_type
|
|
139
139
|
|
|
140
|
-
def description(self, *, is_operation_file: bool) -> str:
|
|
140
|
+
def description(self, *, is_operation_file: bool) -> str:
|
|
141
141
|
possible_values = [self.get_declaration(v.value) for v in self.values]
|
|
142
142
|
if not possible_values:
|
|
143
143
|
return ""
|
|
@@ -21,7 +21,7 @@ class LROPagingOperation(LROOperationBase[LROPagingResponse], PagingOperationBas
|
|
|
21
21
|
return "lropaging"
|
|
22
22
|
|
|
23
23
|
def cls_type_annotation(self, *, async_mode: bool) -> str:
|
|
24
|
-
return f"ClsType[{Response.type_annotation(self.responses[0], async_mode=async_mode)}]"
|
|
24
|
+
return f"ClsType[{Response.type_annotation(self.responses[0], async_mode=async_mode)}]"
|
|
25
25
|
|
|
26
26
|
def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
27
27
|
lro_imports = LROOperationBase.imports(self, async_mode, **kwargs)
|
|
@@ -17,9 +17,9 @@ from .property import Property
|
|
|
17
17
|
from .imports import FileImport, ImportType, TypingSection
|
|
18
18
|
|
|
19
19
|
if sys.version_info >= (3, 8):
|
|
20
|
-
from typing import Literal
|
|
20
|
+
from typing import Literal
|
|
21
21
|
else:
|
|
22
|
-
from typing_extensions import Literal # type: ignore
|
|
22
|
+
from typing_extensions import Literal # type: ignore
|
|
23
23
|
|
|
24
24
|
if TYPE_CHECKING:
|
|
25
25
|
from .code_model import CodeModel
|
|
@@ -50,9 +50,7 @@ def _get_properties(type: "ModelType", properties: List[Property]) -> List[Prope
|
|
|
50
50
|
return properties
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
class ModelType( # pylint: disable=
|
|
54
|
-
BaseType
|
|
55
|
-
): # pylint: disable=too-many-instance-attributes, too-many-public-methods
|
|
53
|
+
class ModelType(BaseType): # pylint: disable=too-many-instance-attributes, too-many-public-methods
|
|
56
54
|
"""Represents a class ready to be serialized in Python.
|
|
57
55
|
|
|
58
56
|
:param str name: The name of the class.
|
|
@@ -89,7 +87,7 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
89
87
|
|
|
90
88
|
@property
|
|
91
89
|
def is_usage_output(self) -> bool:
|
|
92
|
-
return self.usage & UsageFlags.Output.value
|
|
90
|
+
return bool(self.usage & UsageFlags.Output.value)
|
|
93
91
|
|
|
94
92
|
@property
|
|
95
93
|
def flattened_property(self) -> Optional[Property]:
|
|
@@ -284,7 +282,7 @@ class JSONModelType(ModelType):
|
|
|
284
282
|
return file_import
|
|
285
283
|
|
|
286
284
|
|
|
287
|
-
class GeneratedModelType(ModelType):
|
|
285
|
+
class GeneratedModelType(ModelType):
|
|
288
286
|
def type_annotation(self, **kwargs: Any) -> str:
|
|
289
287
|
is_operation_file = kwargs.pop("is_operation_file", False)
|
|
290
288
|
skip_quote = kwargs.get("skip_quote", False)
|
|
@@ -38,6 +38,7 @@ from .parameter_list import ParameterList
|
|
|
38
38
|
from .model_type import ModelType
|
|
39
39
|
from .base import BaseType
|
|
40
40
|
from .request_builder import OverloadedRequestBuilder, RequestBuilder
|
|
41
|
+
from ...utils import xml_serializable, json_serializable
|
|
41
42
|
|
|
42
43
|
if TYPE_CHECKING:
|
|
43
44
|
from .code_model import CodeModel
|
|
@@ -422,14 +423,24 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
422
423
|
if self.parameters.has_body:
|
|
423
424
|
if self.has_form_data_body:
|
|
424
425
|
file_import.add_submodule_import(relative_path, "_model_base", ImportType.LOCAL)
|
|
425
|
-
|
|
426
|
+
elif xml_serializable(self.parameters.body_parameter.default_content_type):
|
|
427
|
+
file_import.add_submodule_import(
|
|
428
|
+
f"{relative_path}_model_base",
|
|
429
|
+
"_get_element",
|
|
430
|
+
ImportType.LOCAL,
|
|
431
|
+
)
|
|
432
|
+
elif json_serializable(self.parameters.body_parameter.default_content_type):
|
|
426
433
|
file_import.add_submodule_import(
|
|
427
434
|
f"{relative_path}_model_base",
|
|
428
435
|
"SdkJSONEncoder",
|
|
429
436
|
ImportType.LOCAL,
|
|
430
437
|
)
|
|
431
438
|
file_import.add_import("json", ImportType.STDLIB)
|
|
432
|
-
if
|
|
439
|
+
if any(xml_serializable(str(r.default_content_type)) for r in self.responses):
|
|
440
|
+
file_import.add_submodule_import(f"{relative_path}_model_base", "_deserialize_xml", ImportType.LOCAL)
|
|
441
|
+
elif any(r.type for r in self.responses):
|
|
442
|
+
file_import.add_submodule_import(f"{relative_path}_model_base", "_deserialize", ImportType.LOCAL)
|
|
443
|
+
if self.default_error_deserialization or self.non_default_errors:
|
|
433
444
|
file_import.add_submodule_import(f"{relative_path}_model_base", "_deserialize", ImportType.LOCAL)
|
|
434
445
|
return file_import
|
|
435
446
|
|
|
@@ -232,7 +232,11 @@ class BodyParameter(_ParameterBase):
|
|
|
232
232
|
def is_form_data(self) -> bool:
|
|
233
233
|
# hacky, but rn in legacy, there is no formdata model type, it's just a dict
|
|
234
234
|
# with all of the entries splatted out
|
|
235
|
-
return
|
|
235
|
+
return (
|
|
236
|
+
self.type.is_form_data
|
|
237
|
+
or bool(self.entries)
|
|
238
|
+
or ("multipart/form-data" in self.content_types and self.code_model.options["from_typespec"])
|
|
239
|
+
)
|
|
236
240
|
|
|
237
241
|
@property
|
|
238
242
|
def is_partial_body(self) -> bool:
|
|
@@ -261,8 +261,7 @@ class _ParameterListBase(
|
|
|
261
261
|
)
|
|
262
262
|
|
|
263
263
|
|
|
264
|
-
class _ParameterList(_ParameterListBase[Parameter, BodyParameter]):
|
|
265
|
-
"""Base Parameter class for the two operation ParameterLists"""
|
|
264
|
+
class _ParameterList(_ParameterListBase[Parameter, BodyParameter]):
|
|
266
265
|
|
|
267
266
|
@staticmethod
|
|
268
267
|
def parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], Parameter]:
|
|
@@ -285,9 +284,7 @@ class ParameterList(_ParameterList):
|
|
|
285
284
|
"""ParameterList is the parameter list for Operation classes"""
|
|
286
285
|
|
|
287
286
|
|
|
288
|
-
class _RequestBuilderParameterList(
|
|
289
|
-
_ParameterListBase[RequestBuilderParameter, RequestBuilderBodyParameter] # pylint: disable=unsubscriptable-object
|
|
290
|
-
):
|
|
287
|
+
class _RequestBuilderParameterList(_ParameterListBase[RequestBuilderParameter, RequestBuilderBodyParameter]):
|
|
291
288
|
"""_RequestBuilderParameterList is base parameter list for RequestBuilder classes"""
|
|
292
289
|
|
|
293
290
|
@staticmethod
|
|
@@ -22,8 +22,8 @@ class RawString(object):
|
|
|
22
22
|
return "r'{}'".format(self.string.replace("'", "\\'"))
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
class PrimitiveType(BaseType):
|
|
26
|
-
def description(self, *, is_operation_file: bool) -> str:
|
|
25
|
+
class PrimitiveType(BaseType):
|
|
26
|
+
def description(self, *, is_operation_file: bool) -> str:
|
|
27
27
|
return ""
|
|
28
28
|
|
|
29
29
|
def type_annotation(self, **kwargs: Any) -> str:
|
|
@@ -188,7 +188,7 @@ class AnyObjectType(PrimitiveType):
|
|
|
188
188
|
return "JSON"
|
|
189
189
|
|
|
190
190
|
|
|
191
|
-
class NumberType(PrimitiveType):
|
|
191
|
+
class NumberType(PrimitiveType):
|
|
192
192
|
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
193
193
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
194
194
|
self.precision: Optional[int] = yaml_data.get("precision")
|
|
@@ -233,6 +233,12 @@ class NumberType(PrimitiveType): # pylint: disable=abstract-method
|
|
|
233
233
|
|
|
234
234
|
|
|
235
235
|
class IntegerType(NumberType):
|
|
236
|
+
|
|
237
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
238
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
239
|
+
if yaml_data.get("encode") == "string":
|
|
240
|
+
self.encode = "str"
|
|
241
|
+
|
|
236
242
|
@property
|
|
237
243
|
def serialization_type(self) -> str:
|
|
238
244
|
return "int"
|
|
@@ -605,6 +611,7 @@ class SdkCoreType(PrimitiveType):
|
|
|
605
611
|
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
606
612
|
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
607
613
|
self.name = yaml_data.get("name", "")
|
|
614
|
+
self.submodule = yaml_data.get("submodule", "")
|
|
608
615
|
|
|
609
616
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
610
617
|
return f"~{self.code_model.core_library}.{self.type_annotation(**kwargs)}"
|
|
@@ -614,7 +621,7 @@ class SdkCoreType(PrimitiveType):
|
|
|
614
621
|
|
|
615
622
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
616
623
|
file_import = super().imports(**kwargs)
|
|
617
|
-
file_import.add_submodule_import(
|
|
624
|
+
file_import.add_submodule_import(self.submodule, self.name, ImportType.SDKCORE)
|
|
618
625
|
return file_import
|
|
619
626
|
|
|
620
627
|
@property
|
|
@@ -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, Dict, Optional, TYPE_CHECKING, List, cast
|
|
6
|
+
from typing import Any, Dict, Optional, TYPE_CHECKING, List, cast, Union
|
|
7
7
|
|
|
8
8
|
from .base import BaseModel
|
|
9
9
|
from .constant_type import ConstantType
|
|
@@ -96,6 +96,10 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
96
96
|
return self.is_polymorphic and self.client_default_value is None
|
|
97
97
|
return self.is_discriminator and self.is_polymorphic and cast(ConstantType, self.type).value is None
|
|
98
98
|
|
|
99
|
+
@property
|
|
100
|
+
def xml_metadata(self) -> Optional[Dict[str, Union[str, bool]]]:
|
|
101
|
+
return self.yaml_data.get("xmlMetadata")
|
|
102
|
+
|
|
99
103
|
def type_annotation(self, *, is_operation_file: bool = False) -> str:
|
|
100
104
|
if self.is_base_discriminator:
|
|
101
105
|
return "str"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# pylint: disable=too-many-lines
|
|
1
|
+
# pylint: disable=too-many-lines
|
|
2
2
|
# -------------------------------------------------------------------------
|
|
3
3
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
@@ -23,7 +23,6 @@ from ..models import (
|
|
|
23
23
|
BinaryType,
|
|
24
24
|
BodyParameter,
|
|
25
25
|
ParameterMethodLocation,
|
|
26
|
-
RequestBuilderBodyParameter,
|
|
27
26
|
OverloadedRequestBuilder,
|
|
28
27
|
Property,
|
|
29
28
|
RequestBuilderType,
|
|
@@ -36,7 +35,7 @@ from ..models import (
|
|
|
36
35
|
from .parameter_serializer import ParameterSerializer, PopKwargType
|
|
37
36
|
from ..models.parameter_list import ParameterType
|
|
38
37
|
from . import utils
|
|
39
|
-
from ...utils import
|
|
38
|
+
from ...utils import xml_serializable, json_serializable
|
|
40
39
|
|
|
41
40
|
T = TypeVar("T")
|
|
42
41
|
OrderedSet = Dict[T, None]
|
|
@@ -62,10 +61,6 @@ def _all_same(data: List[List[str]]) -> bool:
|
|
|
62
61
|
return len(data) > 1 and all(sorted(data[0]) == sorted(data[i]) for i in range(1, len(data)))
|
|
63
62
|
|
|
64
63
|
|
|
65
|
-
def _json_serializable(content_type: str) -> bool:
|
|
66
|
-
return bool(JSON_REGEXP.match(content_type.split(";")[0].strip().lower()))
|
|
67
|
-
|
|
68
|
-
|
|
69
64
|
def _need_type_ignore(builder: OperationType) -> bool:
|
|
70
65
|
for excep in builder.non_default_errors:
|
|
71
66
|
for status_code in excep.status_codes:
|
|
@@ -218,7 +213,7 @@ def is_json_model_type(parameters: ParameterListType) -> bool:
|
|
|
218
213
|
)
|
|
219
214
|
|
|
220
215
|
|
|
221
|
-
class _BuilderBaseSerializer(Generic[BuilderType]):
|
|
216
|
+
class _BuilderBaseSerializer(Generic[BuilderType]):
|
|
222
217
|
def __init__(self, code_model: CodeModel, async_mode: bool) -> None:
|
|
223
218
|
self.code_model = code_model
|
|
224
219
|
self.async_mode = async_mode
|
|
@@ -391,7 +386,7 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
391
386
|
############################## REQUEST BUILDERS ##############################
|
|
392
387
|
|
|
393
388
|
|
|
394
|
-
class RequestBuilderSerializer(_BuilderBaseSerializer[RequestBuilderType]):
|
|
389
|
+
class RequestBuilderSerializer(_BuilderBaseSerializer[RequestBuilderType]):
|
|
395
390
|
def description_and_summary(self, builder: RequestBuilderType) -> List[str]:
|
|
396
391
|
retval = super().description_and_summary(builder)
|
|
397
392
|
retval += [
|
|
@@ -414,7 +409,9 @@ class RequestBuilderSerializer(_BuilderBaseSerializer[RequestBuilderType]): # p
|
|
|
414
409
|
return "response.json()"
|
|
415
410
|
|
|
416
411
|
@staticmethod
|
|
417
|
-
def declare_non_inputtable_headers_queries(
|
|
412
|
+
def declare_non_inputtable_headers_queries(
|
|
413
|
+
builder: RequestBuilderType,
|
|
414
|
+
) -> List[str]:
|
|
418
415
|
def _get_value(param):
|
|
419
416
|
declaration = param.get_declaration() if param.constant else None
|
|
420
417
|
if param.location in [ParameterLocation.HEADER, ParameterLocation.QUERY]:
|
|
@@ -517,7 +514,7 @@ class RequestBuilderSerializer(_BuilderBaseSerializer[RequestBuilderType]): # p
|
|
|
517
514
|
############################## NORMAL OPERATIONS ##############################
|
|
518
515
|
|
|
519
516
|
|
|
520
|
-
class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
|
|
517
|
+
class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
|
|
521
518
|
def description_and_summary(self, builder: OperationType) -> List[str]:
|
|
522
519
|
retval = super().description_and_summary(builder)
|
|
523
520
|
if builder.deprecated:
|
|
@@ -689,7 +686,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]): # pylint: di
|
|
|
689
686
|
f"'{body_param.type.serialization_type}'{is_xml_cmd}{serialization_ctxt_cmd})"
|
|
690
687
|
)
|
|
691
688
|
elif self.code_model.options["models_mode"] == "dpg":
|
|
692
|
-
if
|
|
689
|
+
if json_serializable(body_param.default_content_type):
|
|
693
690
|
if hasattr(body_param.type, "encode") and body_param.type.encode: # type: ignore
|
|
694
691
|
create_body_call = (
|
|
695
692
|
f"_{body_kwarg_name} = json.dumps({body_param.client_name}, "
|
|
@@ -701,6 +698,8 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]): # pylint: di
|
|
|
701
698
|
f"_{body_kwarg_name} = json.dumps({body_param.client_name}, "
|
|
702
699
|
"cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore"
|
|
703
700
|
)
|
|
701
|
+
elif xml_serializable(body_param.default_content_type):
|
|
702
|
+
create_body_call = f"_{body_kwarg_name} = _get_element({body_param.client_name})"
|
|
704
703
|
else:
|
|
705
704
|
create_body_call = f"_{body_kwarg_name} = {body_param.client_name}"
|
|
706
705
|
else:
|
|
@@ -842,14 +841,14 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]): # pylint: di
|
|
|
842
841
|
elif request_builder.overloads:
|
|
843
842
|
seen_body_params = set()
|
|
844
843
|
for overload in request_builder.overloads:
|
|
845
|
-
body_param =
|
|
844
|
+
body_param = overload.parameters.body_parameter
|
|
846
845
|
if body_param.client_name in seen_body_params:
|
|
847
846
|
continue
|
|
848
847
|
seen_body_params.add(body_param.client_name)
|
|
849
848
|
|
|
850
849
|
retval.append(f" {body_param.client_name}={body_param.name_in_high_level_operation},")
|
|
851
850
|
elif request_builder.parameters.has_body:
|
|
852
|
-
body_param =
|
|
851
|
+
body_param = request_builder.parameters.body_parameter
|
|
853
852
|
retval.append(f" {body_param.client_name}={body_param.name_in_high_level_operation},")
|
|
854
853
|
retval.append(" headers=_headers,")
|
|
855
854
|
retval.append(" params=_params,")
|
|
@@ -871,7 +870,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]): # pylint: di
|
|
|
871
870
|
)
|
|
872
871
|
return retval
|
|
873
872
|
|
|
874
|
-
def _call_request_builder_helper(
|
|
873
|
+
def _call_request_builder_helper(
|
|
875
874
|
self,
|
|
876
875
|
builder: OperationType,
|
|
877
876
|
request_builder: RequestBuilderType,
|
|
@@ -962,8 +961,11 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]): # pylint: di
|
|
|
962
961
|
and response.default_content_type == "application/json"
|
|
963
962
|
else ""
|
|
964
963
|
)
|
|
965
|
-
response_attr = "json" if
|
|
966
|
-
|
|
964
|
+
response_attr = "json" if json_serializable(str(response.default_content_type)) else "text"
|
|
965
|
+
deserialize_func = "_deserialize"
|
|
966
|
+
if xml_serializable(str(response.default_content_type)):
|
|
967
|
+
deserialize_func = "_deserialize_xml"
|
|
968
|
+
deserialize_code.append(f"deserialized = {deserialize_func}(")
|
|
967
969
|
deserialize_code.append(
|
|
968
970
|
f" {response.type.type_annotation(is_operation_file=True)},{pylint_disable}"
|
|
969
971
|
)
|
|
@@ -1031,7 +1033,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]): # pylint: di
|
|
|
1031
1033
|
retval.append("deserialized = None")
|
|
1032
1034
|
if builder.any_response_has_headers:
|
|
1033
1035
|
retval.append("response_headers = {}")
|
|
1034
|
-
if builder.has_response_body or builder.any_response_has_headers:
|
|
1036
|
+
if builder.has_response_body or builder.any_response_has_headers: # pylint: disable=too-many-nested-blocks
|
|
1035
1037
|
if len(builder.responses) > 1:
|
|
1036
1038
|
status_codes, res_headers, res_deserialization = [], [], []
|
|
1037
1039
|
for status_code in builder.success_status_codes:
|
|
@@ -1173,7 +1175,7 @@ class OperationSerializer(_OperationSerializer[Operation]): ...
|
|
|
1173
1175
|
PagingOperationType = TypeVar("PagingOperationType", bound=Union[PagingOperation, LROPagingOperation])
|
|
1174
1176
|
|
|
1175
1177
|
|
|
1176
|
-
class _PagingOperationSerializer(_OperationSerializer[PagingOperationType]):
|
|
1178
|
+
class _PagingOperationSerializer(_OperationSerializer[PagingOperationType]):
|
|
1177
1179
|
def __init__(self, code_model: CodeModel, async_mode: bool) -> None:
|
|
1178
1180
|
# for pylint reasons need to redefine init
|
|
1179
1181
|
# probably because inheritance is going too deep
|
|
@@ -1458,7 +1460,7 @@ class LROOperationSerializer(_LROOperationSerializer[LROOperation]): ...
|
|
|
1458
1460
|
class LROPagingOperationSerializer(
|
|
1459
1461
|
_LROOperationSerializer[LROPagingOperation],
|
|
1460
1462
|
_PagingOperationSerializer[LROPagingOperation],
|
|
1461
|
-
):
|
|
1463
|
+
):
|
|
1462
1464
|
@property
|
|
1463
1465
|
def _call_method(self) -> str:
|
|
1464
1466
|
return "await " if self.async_mode else ""
|
|
@@ -182,12 +182,13 @@ class GeneralSerializer(BaseSerializer):
|
|
|
182
182
|
def serialize_cross_language_definition_file(self) -> str:
|
|
183
183
|
cross_langauge_def_dict = {
|
|
184
184
|
f"{self.code_model.namespace}.models.{model.name}": model.cross_language_definition_id
|
|
185
|
-
for model in self.code_model.
|
|
185
|
+
for model in self.code_model.public_model_types
|
|
186
186
|
}
|
|
187
187
|
cross_langauge_def_dict.update(
|
|
188
188
|
{
|
|
189
189
|
f"{self.code_model.namespace}.models.{enum.name}": enum.cross_language_definition_id
|
|
190
190
|
for enum in self.code_model.enums
|
|
191
|
+
if not enum.internal
|
|
191
192
|
}
|
|
192
193
|
)
|
|
193
194
|
cross_langauge_def_dict.update(
|
|
@@ -251,6 +251,9 @@ class DpgModelSerializer(_ModelSerializer):
|
|
|
251
251
|
elif hasattr(prop.type, "encode") and prop.type.encode: # type: ignore
|
|
252
252
|
args.append(f'format="{prop.type.encode}"') # type: ignore
|
|
253
253
|
|
|
254
|
+
if prop.xml_metadata:
|
|
255
|
+
args.append(f"xml={prop.xml_metadata}")
|
|
256
|
+
|
|
254
257
|
field = "rest_discriminator" if prop.is_discriminator else "rest_field"
|
|
255
258
|
type_ignore = prop.is_discriminator and isinstance(prop.type, (ConstantType, EnumValue)) and prop.type.value
|
|
256
259
|
return (
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# pylint: disable=too-many-lines
|
|
2
1
|
# -------------------------------------------------------------------------
|
|
3
2
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
@@ -22,7 +21,6 @@ from ..models import (
|
|
|
22
21
|
FileImport,
|
|
23
22
|
)
|
|
24
23
|
from .utils import get_namespace_config, get_namespace_from_package_name
|
|
25
|
-
from ...utils import to_snake_case
|
|
26
24
|
|
|
27
25
|
_LOGGER = logging.getLogger(__name__)
|
|
28
26
|
|
|
@@ -152,7 +150,7 @@ class SampleSerializer(BaseSerializer):
|
|
|
152
150
|
name = self.sample.get("x-ms-original-file", "")
|
|
153
151
|
if "specification" in name:
|
|
154
152
|
return "specification" + name.split("specification")[-1]
|
|
155
|
-
return ""
|
|
153
|
+
return name if self.code_model.options["from_typespec"] else ""
|
|
156
154
|
|
|
157
155
|
def serialize(self) -> str:
|
|
158
156
|
operation_result, return_var = self._operation_result()
|
|
@@ -80,6 +80,12 @@ class TestCase:
|
|
|
80
80
|
self.operation = operation
|
|
81
81
|
self.is_async = is_async
|
|
82
82
|
|
|
83
|
+
@property
|
|
84
|
+
def name(self) -> str:
|
|
85
|
+
if self.operation_groups[-1].is_mixin:
|
|
86
|
+
return self.operation.name
|
|
87
|
+
return "_".join([og.property_name for og in self.operation_groups] + [self.operation.name])
|
|
88
|
+
|
|
83
89
|
@property
|
|
84
90
|
def operation_group_prefix(self) -> str:
|
|
85
91
|
if self.operation_groups[-1].is_mixin:
|