@autorest/python 6.2.0 → 6.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autorest/codegen/__init__.py +9 -74
- package/autorest/codegen/models/__init__.py +11 -12
- package/autorest/codegen/models/{base_type.py → base.py} +29 -10
- package/autorest/codegen/models/base_builder.py +8 -10
- package/autorest/codegen/models/client.py +111 -40
- package/autorest/codegen/models/code_model.py +131 -90
- package/autorest/codegen/models/combined_type.py +7 -7
- package/autorest/codegen/models/constant_type.py +44 -10
- package/autorest/codegen/models/credential_types.py +17 -19
- package/autorest/codegen/models/dictionary_type.py +7 -9
- package/autorest/codegen/models/enum_type.py +19 -24
- package/autorest/codegen/models/imports.py +82 -33
- package/autorest/codegen/models/list_type.py +11 -15
- package/autorest/codegen/models/lro_operation.py +6 -10
- package/autorest/codegen/models/model_type.py +20 -21
- package/autorest/codegen/models/operation.py +49 -42
- package/autorest/codegen/models/operation_group.py +11 -11
- package/autorest/codegen/models/paging_operation.py +9 -11
- package/autorest/codegen/models/parameter.py +48 -32
- package/autorest/codegen/models/parameter_list.py +16 -22
- package/autorest/codegen/models/primitive_types.py +12 -23
- package/autorest/codegen/models/property.py +11 -11
- package/autorest/codegen/models/request_builder.py +19 -19
- package/autorest/codegen/models/request_builder_parameter.py +14 -16
- package/autorest/codegen/models/response.py +24 -28
- package/autorest/codegen/serializers/__init__.py +202 -187
- package/autorest/codegen/serializers/builder_serializer.py +49 -50
- package/autorest/codegen/serializers/client_serializer.py +9 -7
- package/autorest/codegen/serializers/enum_serializer.py +4 -4
- package/autorest/codegen/serializers/general_serializer.py +26 -36
- package/autorest/codegen/serializers/import_serializer.py +30 -36
- package/autorest/codegen/serializers/metadata_serializer.py +35 -17
- package/autorest/codegen/serializers/model_init_serializer.py +6 -10
- package/autorest/codegen/serializers/model_serializer.py +42 -27
- package/autorest/codegen/serializers/operation_groups_serializer.py +12 -8
- package/autorest/codegen/serializers/operations_init_serializer.py +13 -6
- package/autorest/codegen/serializers/patch_serializer.py +4 -4
- package/autorest/codegen/serializers/request_builders_serializer.py +6 -6
- package/autorest/codegen/serializers/sample_serializer.py +10 -12
- package/autorest/codegen/templates/client_container.py.jinja2 +2 -2
- package/autorest/codegen/templates/config.py.jinja2 +1 -1
- package/autorest/codegen/templates/config_container.py.jinja2 +3 -3
- package/autorest/codegen/templates/enum_container.py.jinja2 +2 -2
- package/autorest/codegen/templates/init.py.jinja2 +2 -2
- package/autorest/codegen/templates/lro_operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/metadata.json.jinja2 +2 -2
- package/autorest/codegen/templates/model_container.py.jinja2 +3 -3
- package/autorest/codegen/templates/model_dpg.py.jinja2 +4 -4
- package/autorest/codegen/templates/model_init.py.jinja2 +3 -3
- package/autorest/codegen/templates/operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_group.py.jinja2 +2 -2
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +3 -3
- package/autorest/codegen/templates/operation_tools.jinja2 +3 -3
- package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -4
- package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +4 -1
- package/autorest/codegen/templates/paging_operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/request_builder.py.jinja2 +1 -1
- package/autorest/codegen/templates/request_builders.py.jinja2 +2 -2
- package/autorest/codegen/templates/rest_init.py.jinja2 +1 -1
- package/autorest/codegen/templates/sample.py.jinja2 +5 -5
- package/autorest/codegen/templates/validation.py.jinja2 +1 -1
- package/autorest/codegen/templates/vendor.py.jinja2 +6 -6
- package/autorest/codegen/templates/version.py.jinja2 +2 -2
- package/autorest/m4reformatter/__init__.py +57 -47
- package/autorest/multiapi/models/imports.py +89 -18
- package/autorest/multiapi/serializers/import_serializer.py +88 -7
- package/autorest/multiapi/utils.py +6 -0
- package/autorest/preprocess/__init__.py +23 -26
- package/package.json +1 -1
- package/run_cadl.py +0 -1
- package/autorest/cadlflags/__init__.py +0 -130
- package/autorest/codegen/models/base_model.py +0 -30
|
@@ -49,7 +49,7 @@ RequestBuilderBodyParameterType = Union[
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
if TYPE_CHECKING:
|
|
52
|
-
from .code_model import
|
|
52
|
+
from .code_model import CodeModel
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
class ParameterImplementation(Enum):
|
|
@@ -81,12 +81,12 @@ class _ParameterListBase(
|
|
|
81
81
|
def __init__(
|
|
82
82
|
self,
|
|
83
83
|
yaml_data: Dict[str, Any],
|
|
84
|
-
|
|
84
|
+
code_model: "CodeModel",
|
|
85
85
|
parameters: List[ParameterType],
|
|
86
86
|
body_parameter: Optional[BodyParameterType] = None,
|
|
87
87
|
) -> None:
|
|
88
88
|
self.yaml_data = yaml_data
|
|
89
|
-
self.
|
|
89
|
+
self.code_model = code_model
|
|
90
90
|
self.parameters = parameters or []
|
|
91
91
|
self._body_parameter = body_parameter
|
|
92
92
|
|
|
@@ -113,16 +113,14 @@ class _ParameterListBase(
|
|
|
113
113
|
|
|
114
114
|
@staticmethod
|
|
115
115
|
@abstractmethod
|
|
116
|
-
def parameter_creator() -> Callable[
|
|
117
|
-
[Dict[str, Any], "NamespaceModel"], ParameterType
|
|
118
|
-
]:
|
|
116
|
+
def parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], ParameterType]:
|
|
119
117
|
"""Callable for creating parameters"""
|
|
120
118
|
...
|
|
121
119
|
|
|
122
120
|
@staticmethod
|
|
123
121
|
@abstractmethod
|
|
124
122
|
def body_parameter_creator() -> Callable[
|
|
125
|
-
[Dict[str, Any], "
|
|
123
|
+
[Dict[str, Any], "CodeModel"], BodyParameterType
|
|
126
124
|
]:
|
|
127
125
|
"""Callable for creating body parameters"""
|
|
128
126
|
...
|
|
@@ -292,19 +290,19 @@ class _ParameterListBase(
|
|
|
292
290
|
return retval
|
|
293
291
|
|
|
294
292
|
@classmethod
|
|
295
|
-
def from_yaml(cls, yaml_data: Dict[str, Any],
|
|
293
|
+
def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel"):
|
|
296
294
|
parameters = [
|
|
297
|
-
cls.parameter_creator()(parameter,
|
|
295
|
+
cls.parameter_creator()(parameter, code_model)
|
|
298
296
|
for parameter in yaml_data["parameters"]
|
|
299
297
|
]
|
|
300
298
|
body_parameter = None
|
|
301
299
|
if yaml_data.get("bodyParameter"):
|
|
302
300
|
body_parameter = cls.body_parameter_creator()(
|
|
303
|
-
yaml_data["bodyParameter"],
|
|
301
|
+
yaml_data["bodyParameter"], code_model
|
|
304
302
|
)
|
|
305
303
|
return cls(
|
|
306
304
|
yaml_data,
|
|
307
|
-
|
|
305
|
+
code_model,
|
|
308
306
|
parameters=parameters,
|
|
309
307
|
body_parameter=body_parameter,
|
|
310
308
|
)
|
|
@@ -318,12 +316,12 @@ class _ParameterList(
|
|
|
318
316
|
"""Base Parameter class for the two operation ParameterLists"""
|
|
319
317
|
|
|
320
318
|
@staticmethod
|
|
321
|
-
def parameter_creator() -> Callable[[Dict[str, Any], "
|
|
319
|
+
def parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], Parameter]:
|
|
322
320
|
return Parameter.from_yaml
|
|
323
321
|
|
|
324
322
|
@staticmethod
|
|
325
323
|
def body_parameter_creator() -> Callable[
|
|
326
|
-
[Dict[str, Any], "
|
|
324
|
+
[Dict[str, Any], "CodeModel"], Union[MultipartBodyParameter, BodyParameter]
|
|
327
325
|
]:
|
|
328
326
|
return get_body_parameter
|
|
329
327
|
|
|
@@ -353,13 +351,13 @@ class _RequestBuilderParameterList(
|
|
|
353
351
|
|
|
354
352
|
@staticmethod
|
|
355
353
|
def parameter_creator() -> Callable[
|
|
356
|
-
[Dict[str, Any], "
|
|
354
|
+
[Dict[str, Any], "CodeModel"], RequestBuilderParameter
|
|
357
355
|
]:
|
|
358
356
|
return RequestBuilderParameter.from_yaml
|
|
359
357
|
|
|
360
358
|
@staticmethod
|
|
361
359
|
def body_parameter_creator() -> Callable[
|
|
362
|
-
[Dict[str, Any], "
|
|
360
|
+
[Dict[str, Any], "CodeModel"], RequestBuilderBodyParameterType
|
|
363
361
|
]:
|
|
364
362
|
return get_request_body_parameter
|
|
365
363
|
|
|
@@ -424,7 +422,7 @@ class _ClientGlobalParameterList(
|
|
|
424
422
|
|
|
425
423
|
@staticmethod
|
|
426
424
|
def body_parameter_creator() -> Callable[
|
|
427
|
-
[Dict[str, Any], "
|
|
425
|
+
[Dict[str, Any], "CodeModel"], BodyParameter
|
|
428
426
|
]:
|
|
429
427
|
return BodyParameter.from_yaml
|
|
430
428
|
|
|
@@ -450,9 +448,7 @@ class ClientGlobalParameterList(_ClientGlobalParameterList[ClientParameter]):
|
|
|
450
448
|
"""Parameter list for Client class"""
|
|
451
449
|
|
|
452
450
|
@staticmethod
|
|
453
|
-
def parameter_creator() -> Callable[
|
|
454
|
-
[Dict[str, Any], "NamespaceModel"], ClientParameter
|
|
455
|
-
]:
|
|
451
|
+
def parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], ClientParameter]:
|
|
456
452
|
return ClientParameter.from_yaml
|
|
457
453
|
|
|
458
454
|
@property
|
|
@@ -481,9 +477,7 @@ class ConfigGlobalParameterList(_ClientGlobalParameterList[ConfigParameter]):
|
|
|
481
477
|
"""Parameter list for config"""
|
|
482
478
|
|
|
483
479
|
@staticmethod
|
|
484
|
-
def parameter_creator() -> Callable[
|
|
485
|
-
[Dict[str, Any], "NamespaceModel"], ConfigParameter
|
|
486
|
-
]:
|
|
480
|
+
def parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], ConfigParameter]:
|
|
487
481
|
return ConfigParameter.from_yaml
|
|
488
482
|
|
|
489
483
|
@property
|
|
@@ -7,12 +7,12 @@ import datetime
|
|
|
7
7
|
from enum import Enum
|
|
8
8
|
from typing import Any, Dict, List, Optional, Union, TYPE_CHECKING
|
|
9
9
|
|
|
10
|
-
from .
|
|
10
|
+
from .base import BaseType
|
|
11
11
|
from .imports import FileImport, ImportType, TypingSection
|
|
12
12
|
from .utils import add_to_description
|
|
13
13
|
|
|
14
14
|
if TYPE_CHECKING:
|
|
15
|
-
from .code_model import
|
|
15
|
+
from .code_model import CodeModel
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class RawString(object):
|
|
@@ -83,10 +83,8 @@ class BooleanType(PrimitiveType):
|
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
class BinaryType(PrimitiveType):
|
|
86
|
-
def __init__(
|
|
87
|
-
|
|
88
|
-
) -> None:
|
|
89
|
-
super().__init__(yaml_data=yaml_data, namespace_model=namespace_model)
|
|
86
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
87
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
90
88
|
self.type = "IO"
|
|
91
89
|
|
|
92
90
|
@property
|
|
@@ -199,15 +197,12 @@ class AnyObjectType(PrimitiveType):
|
|
|
199
197
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
200
198
|
file_import = FileImport()
|
|
201
199
|
file_import.define_mutable_mapping_type()
|
|
202
|
-
file_import.add_import("sys", ImportType.STDLIB)
|
|
203
200
|
return file_import
|
|
204
201
|
|
|
205
202
|
|
|
206
203
|
class NumberType(PrimitiveType): # pylint: disable=abstract-method
|
|
207
|
-
def __init__(
|
|
208
|
-
|
|
209
|
-
) -> None:
|
|
210
|
-
super().__init__(yaml_data=yaml_data, namespace_model=namespace_model)
|
|
204
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
205
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
211
206
|
self.precision: Optional[int] = yaml_data.get("precision")
|
|
212
207
|
self.multiple: Optional[int] = yaml_data.get("multipleOf")
|
|
213
208
|
self.maximum: Optional[int] = yaml_data.get("maximum")
|
|
@@ -298,10 +293,8 @@ class FloatType(NumberType):
|
|
|
298
293
|
|
|
299
294
|
|
|
300
295
|
class StringType(PrimitiveType):
|
|
301
|
-
def __init__(
|
|
302
|
-
|
|
303
|
-
) -> None:
|
|
304
|
-
super().__init__(yaml_data=yaml_data, namespace_model=namespace_model)
|
|
296
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
297
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
305
298
|
self.max_length: Optional[int] = yaml_data.get("maxLength")
|
|
306
299
|
self.min_length: Optional[int] = (
|
|
307
300
|
yaml_data.get("minLength", 0)
|
|
@@ -347,10 +340,8 @@ class StringType(PrimitiveType):
|
|
|
347
340
|
|
|
348
341
|
|
|
349
342
|
class DatetimeType(PrimitiveType):
|
|
350
|
-
def __init__(
|
|
351
|
-
|
|
352
|
-
) -> None:
|
|
353
|
-
super().__init__(yaml_data=yaml_data, namespace_model=namespace_model)
|
|
343
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
344
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
354
345
|
self.format = self.Formats(yaml_data["format"])
|
|
355
346
|
|
|
356
347
|
class Formats(str, Enum):
|
|
@@ -531,10 +522,8 @@ class DurationType(PrimitiveType):
|
|
|
531
522
|
|
|
532
523
|
|
|
533
524
|
class ByteArraySchema(PrimitiveType):
|
|
534
|
-
def __init__(
|
|
535
|
-
|
|
536
|
-
) -> None:
|
|
537
|
-
super().__init__(yaml_data=yaml_data, namespace_model=namespace_model)
|
|
525
|
+
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
526
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
538
527
|
self.format = yaml_data["format"]
|
|
539
528
|
|
|
540
529
|
@property
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
from typing import Any, Dict, Optional, TYPE_CHECKING, List
|
|
7
7
|
|
|
8
|
-
from .
|
|
8
|
+
from .base import BaseModel
|
|
9
9
|
from .constant_type import ConstantType
|
|
10
|
-
from .
|
|
10
|
+
from .base import BaseType
|
|
11
11
|
from .imports import FileImport, ImportType, TypingSection
|
|
12
12
|
from .utils import add_to_description, add_to_pylint_disable
|
|
13
13
|
|
|
14
14
|
if TYPE_CHECKING:
|
|
15
|
-
from .code_model import
|
|
15
|
+
from .code_model import CodeModel
|
|
16
16
|
from .model_type import ModelType
|
|
17
17
|
|
|
18
18
|
|
|
@@ -20,10 +20,10 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
20
20
|
def __init__(
|
|
21
21
|
self,
|
|
22
22
|
yaml_data: Dict[str, Any],
|
|
23
|
-
|
|
23
|
+
code_model: "CodeModel",
|
|
24
24
|
type: BaseType,
|
|
25
25
|
) -> None:
|
|
26
|
-
super().__init__(yaml_data,
|
|
26
|
+
super().__init__(yaml_data, code_model)
|
|
27
27
|
self.rest_api_name: str = self.yaml_data["restApiName"]
|
|
28
28
|
self.client_name: str = self.yaml_data["clientName"]
|
|
29
29
|
self.type = type
|
|
@@ -125,10 +125,10 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
125
125
|
retval.update(self.type.validation or {})
|
|
126
126
|
return retval or None
|
|
127
127
|
|
|
128
|
-
def imports(self) -> FileImport:
|
|
128
|
+
def imports(self, **kwargs) -> FileImport:
|
|
129
129
|
from .model_type import ModelType
|
|
130
130
|
|
|
131
|
-
file_import = self.type.imports(is_operation_file=False)
|
|
131
|
+
file_import = self.type.imports(**kwargs, is_operation_file=False)
|
|
132
132
|
if self.optional and self.client_default_value is None:
|
|
133
133
|
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
|
|
134
134
|
if isinstance(self.type, ModelType):
|
|
@@ -139,7 +139,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
139
139
|
TypingSection.TYPING,
|
|
140
140
|
alias="_models",
|
|
141
141
|
)
|
|
142
|
-
if self.
|
|
142
|
+
if self.code_model.options["models_mode"] == "dpg":
|
|
143
143
|
file_import.add_submodule_import(
|
|
144
144
|
".._model_base",
|
|
145
145
|
"rest_discriminator" if self.is_discriminator else "rest_field",
|
|
@@ -151,12 +151,12 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
151
151
|
def from_yaml(
|
|
152
152
|
cls,
|
|
153
153
|
yaml_data: Dict[str, Any],
|
|
154
|
-
|
|
154
|
+
code_model: "CodeModel",
|
|
155
155
|
) -> "Property":
|
|
156
156
|
from . import build_type # pylint: disable=import-outside-toplevel
|
|
157
157
|
|
|
158
158
|
return cls(
|
|
159
159
|
yaml_data=yaml_data,
|
|
160
|
-
|
|
161
|
-
type=build_type(yaml_data["type"],
|
|
160
|
+
code_model=code_model,
|
|
161
|
+
type=build_type(yaml_data["type"], code_model),
|
|
162
162
|
)
|
|
@@ -23,7 +23,7 @@ from .parameter_list import (
|
|
|
23
23
|
from .imports import FileImport, ImportType, TypingSection, MsrestImportType
|
|
24
24
|
|
|
25
25
|
if TYPE_CHECKING:
|
|
26
|
-
from .code_model import
|
|
26
|
+
from .code_model import CodeModel
|
|
27
27
|
from .client import Client
|
|
28
28
|
|
|
29
29
|
ParameterListType = TypeVar(
|
|
@@ -36,7 +36,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
36
36
|
def __init__(
|
|
37
37
|
self,
|
|
38
38
|
yaml_data: Dict[str, Any],
|
|
39
|
-
|
|
39
|
+
code_model: "CodeModel",
|
|
40
40
|
client: "Client",
|
|
41
41
|
name: str,
|
|
42
42
|
parameters: ParameterListType,
|
|
@@ -44,7 +44,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
44
44
|
overloads: Optional[List["RequestBuilder"]] = None,
|
|
45
45
|
) -> None:
|
|
46
46
|
super().__init__(
|
|
47
|
-
|
|
47
|
+
code_model=code_model,
|
|
48
48
|
client=client,
|
|
49
49
|
yaml_data=yaml_data,
|
|
50
50
|
name=name,
|
|
@@ -85,7 +85,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
85
85
|
if self.parameters.path:
|
|
86
86
|
relative_path = ".."
|
|
87
87
|
if (
|
|
88
|
-
not self.
|
|
88
|
+
not self.code_model.options["builders_visibility"] == "embedded"
|
|
89
89
|
and self.group_name
|
|
90
90
|
):
|
|
91
91
|
relative_path = "..." if self.group_name else ".."
|
|
@@ -100,10 +100,10 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
100
100
|
"typing", "Any", ImportType.STDLIB, typing_section=TypingSection.CONDITIONAL
|
|
101
101
|
)
|
|
102
102
|
file_import.add_msrest_import(
|
|
103
|
-
self.
|
|
103
|
+
self.code_model,
|
|
104
104
|
"..."
|
|
105
105
|
if (
|
|
106
|
-
not self.
|
|
106
|
+
not self.code_model.options["builders_visibility"] == "embedded"
|
|
107
107
|
and self.group_name
|
|
108
108
|
)
|
|
109
109
|
else "..",
|
|
@@ -112,7 +112,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
112
112
|
)
|
|
113
113
|
if (
|
|
114
114
|
self.overloads
|
|
115
|
-
and self.
|
|
115
|
+
and self.code_model.options["builders_visibility"] != "embedded"
|
|
116
116
|
):
|
|
117
117
|
file_import.add_submodule_import("typing", "overload", ImportType.STDLIB)
|
|
118
118
|
return file_import
|
|
@@ -120,7 +120,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
120
120
|
@staticmethod
|
|
121
121
|
@abstractmethod
|
|
122
122
|
def parameter_list_type() -> Callable[
|
|
123
|
-
[Dict[str, Any], "
|
|
123
|
+
[Dict[str, Any], "CodeModel"], ParameterListType
|
|
124
124
|
]:
|
|
125
125
|
...
|
|
126
126
|
|
|
@@ -128,15 +128,15 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
128
128
|
def from_yaml(
|
|
129
129
|
cls,
|
|
130
130
|
yaml_data: Dict[str, Any],
|
|
131
|
-
|
|
131
|
+
code_model: "CodeModel",
|
|
132
132
|
client: "Client",
|
|
133
133
|
):
|
|
134
134
|
# when combine embedded builders into one operation file, we need to avoid duplicated build function name.
|
|
135
135
|
# So add operation group name is effective method
|
|
136
136
|
additional_mark = ""
|
|
137
137
|
if (
|
|
138
|
-
|
|
139
|
-
and
|
|
138
|
+
code_model.options["combine_operation_files"]
|
|
139
|
+
and code_model.options["builders_visibility"] == "embedded"
|
|
140
140
|
):
|
|
141
141
|
additional_mark = (
|
|
142
142
|
yaml_data["groupName"] or client.yaml_data["builderPadName"]
|
|
@@ -149,14 +149,14 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
149
149
|
]
|
|
150
150
|
name = "_".join([n for n in names if n])
|
|
151
151
|
overloads = [
|
|
152
|
-
RequestBuilder.from_yaml(rb_yaml_data,
|
|
152
|
+
RequestBuilder.from_yaml(rb_yaml_data, code_model, client)
|
|
153
153
|
for rb_yaml_data in yaml_data.get("overloads", [])
|
|
154
154
|
]
|
|
155
|
-
parameter_list = cls.parameter_list_type()(yaml_data,
|
|
155
|
+
parameter_list = cls.parameter_list_type()(yaml_data, code_model)
|
|
156
156
|
|
|
157
157
|
return cls(
|
|
158
158
|
yaml_data=yaml_data,
|
|
159
|
-
|
|
159
|
+
code_model=code_model,
|
|
160
160
|
client=client,
|
|
161
161
|
name=name,
|
|
162
162
|
parameters=parameter_list,
|
|
@@ -167,7 +167,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
167
167
|
class RequestBuilder(RequestBuilderBase[RequestBuilderParameterList]):
|
|
168
168
|
@staticmethod
|
|
169
169
|
def parameter_list_type() -> Callable[
|
|
170
|
-
[Dict[str, Any], "
|
|
170
|
+
[Dict[str, Any], "CodeModel"], RequestBuilderParameterList
|
|
171
171
|
]:
|
|
172
172
|
return RequestBuilderParameterList.from_yaml
|
|
173
173
|
|
|
@@ -177,14 +177,14 @@ class OverloadedRequestBuilder(
|
|
|
177
177
|
):
|
|
178
178
|
@staticmethod
|
|
179
179
|
def parameter_list_type() -> Callable[
|
|
180
|
-
[Dict[str, Any], "
|
|
180
|
+
[Dict[str, Any], "CodeModel"], OverloadedRequestBuilderParameterList
|
|
181
181
|
]:
|
|
182
182
|
return OverloadedRequestBuilderParameterList.from_yaml
|
|
183
183
|
|
|
184
184
|
|
|
185
185
|
def get_request_builder(
|
|
186
|
-
yaml_data: Dict[str, Any],
|
|
186
|
+
yaml_data: Dict[str, Any], code_model: "CodeModel", client: "Client"
|
|
187
187
|
) -> Union[RequestBuilder, OverloadedRequestBuilder]:
|
|
188
188
|
if yaml_data.get("overloads"):
|
|
189
|
-
return OverloadedRequestBuilder.from_yaml(yaml_data,
|
|
190
|
-
return RequestBuilder.from_yaml(yaml_data,
|
|
189
|
+
return OverloadedRequestBuilder.from_yaml(yaml_data, code_model, client)
|
|
190
|
+
return RequestBuilder.from_yaml(yaml_data, code_model, client)
|
|
@@ -11,12 +11,12 @@ from .parameter import (
|
|
|
11
11
|
BodyParameter,
|
|
12
12
|
_MultipartBodyParameter,
|
|
13
13
|
)
|
|
14
|
-
from .
|
|
14
|
+
from .base import BaseType
|
|
15
15
|
from .primitive_types import BinaryType, StringType
|
|
16
16
|
from .combined_type import CombinedType
|
|
17
17
|
|
|
18
18
|
if TYPE_CHECKING:
|
|
19
|
-
from .code_model import
|
|
19
|
+
from .code_model import CodeModel
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
class RequestBuilderBodyParameter(BodyParameter):
|
|
@@ -27,7 +27,7 @@ class RequestBuilderBodyParameter(BodyParameter):
|
|
|
27
27
|
if (
|
|
28
28
|
isinstance(self.type, (BinaryType, StringType))
|
|
29
29
|
or any("xml" in ct for ct in self.content_types)
|
|
30
|
-
or self.
|
|
30
|
+
or self.code_model.options["models_mode"] == "dpg"
|
|
31
31
|
):
|
|
32
32
|
self.client_name = "content"
|
|
33
33
|
else:
|
|
@@ -52,9 +52,9 @@ class RequestBuilderBodyParameter(BodyParameter):
|
|
|
52
52
|
|
|
53
53
|
@classmethod
|
|
54
54
|
def from_yaml(
|
|
55
|
-
cls, yaml_data: Dict[str, Any],
|
|
55
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
56
56
|
) -> "RequestBuilderBodyParameter":
|
|
57
|
-
return super().from_yaml(yaml_data,
|
|
57
|
+
return super().from_yaml(yaml_data, code_model) # type: ignore
|
|
58
58
|
|
|
59
59
|
@property
|
|
60
60
|
def name_in_high_level_operation(self) -> str:
|
|
@@ -76,14 +76,14 @@ class RequestBuilderMultipartBodyParameter(
|
|
|
76
76
|
|
|
77
77
|
@classmethod
|
|
78
78
|
def from_yaml(
|
|
79
|
-
cls, yaml_data: Dict[str, Any],
|
|
79
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
80
80
|
) -> "RequestBuilderMultipartBodyParameter":
|
|
81
81
|
return cls(
|
|
82
82
|
yaml_data=yaml_data,
|
|
83
|
-
|
|
84
|
-
type=
|
|
83
|
+
code_model=code_model,
|
|
84
|
+
type=code_model.lookup_type(id(yaml_data["type"])),
|
|
85
85
|
entries=[
|
|
86
|
-
RequestBuilderBodyParameter.from_yaml(entry,
|
|
86
|
+
RequestBuilderBodyParameter.from_yaml(entry, code_model)
|
|
87
87
|
for entry in yaml_data["entries"]
|
|
88
88
|
],
|
|
89
89
|
)
|
|
@@ -95,10 +95,10 @@ class RequestBuilderParameter(Parameter):
|
|
|
95
95
|
def __init__(
|
|
96
96
|
self,
|
|
97
97
|
yaml_data: Dict[str, Any],
|
|
98
|
-
|
|
98
|
+
code_model: "CodeModel",
|
|
99
99
|
type: BaseType,
|
|
100
100
|
) -> None:
|
|
101
|
-
super().__init__(yaml_data,
|
|
101
|
+
super().__init__(yaml_data, code_model, type)
|
|
102
102
|
# we don't want any default content type behavior in request builder
|
|
103
103
|
if self.is_content_type:
|
|
104
104
|
self.client_default_value = None
|
|
@@ -144,11 +144,9 @@ class RequestBuilderParameter(Parameter):
|
|
|
144
144
|
|
|
145
145
|
|
|
146
146
|
def get_request_body_parameter(
|
|
147
|
-
yaml_data: Dict[str, Any],
|
|
147
|
+
yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
148
148
|
) -> Union[RequestBuilderBodyParameter, RequestBuilderMultipartBodyParameter]:
|
|
149
149
|
"""Get body parameter for a request builder"""
|
|
150
150
|
if yaml_data.get("entries"):
|
|
151
|
-
return RequestBuilderMultipartBodyParameter.from_yaml(
|
|
152
|
-
|
|
153
|
-
)
|
|
154
|
-
return RequestBuilderBodyParameter.from_yaml(yaml_data, namespace_model)
|
|
151
|
+
return RequestBuilderMultipartBodyParameter.from_yaml(yaml_data, code_model)
|
|
152
|
+
return RequestBuilderBodyParameter.from_yaml(yaml_data, code_model)
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
from typing import Dict, Optional, List, Any, TYPE_CHECKING, Union
|
|
7
7
|
|
|
8
|
-
from .
|
|
9
|
-
from .
|
|
8
|
+
from .base import BaseModel
|
|
9
|
+
from .base import BaseType
|
|
10
10
|
from .imports import FileImport, ImportType
|
|
11
11
|
from .primitive_types import BinaryType, BinaryIteratorType
|
|
12
12
|
from .dictionary_type import DictionaryType
|
|
@@ -14,17 +14,17 @@ from .list_type import ListType
|
|
|
14
14
|
from .model_type import ModelType
|
|
15
15
|
|
|
16
16
|
if TYPE_CHECKING:
|
|
17
|
-
from .code_model import
|
|
17
|
+
from .code_model import CodeModel
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
class ResponseHeader(BaseModel):
|
|
21
21
|
def __init__(
|
|
22
22
|
self,
|
|
23
23
|
yaml_data: Dict[str, Any],
|
|
24
|
-
|
|
24
|
+
code_model: "CodeModel",
|
|
25
25
|
type: BaseType,
|
|
26
26
|
) -> None:
|
|
27
|
-
super().__init__(yaml_data,
|
|
27
|
+
super().__init__(yaml_data, code_model)
|
|
28
28
|
self.rest_api_name: str = yaml_data["restApiName"]
|
|
29
29
|
self.type = type
|
|
30
30
|
|
|
@@ -34,12 +34,12 @@ class ResponseHeader(BaseModel):
|
|
|
34
34
|
|
|
35
35
|
@classmethod
|
|
36
36
|
def from_yaml(
|
|
37
|
-
cls, yaml_data: Dict[str, Any],
|
|
37
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
38
38
|
) -> "ResponseHeader":
|
|
39
39
|
return cls(
|
|
40
40
|
yaml_data=yaml_data,
|
|
41
|
-
|
|
42
|
-
type=
|
|
41
|
+
code_model=code_model,
|
|
42
|
+
type=code_model.lookup_type(id(yaml_data["type"])),
|
|
43
43
|
)
|
|
44
44
|
|
|
45
45
|
|
|
@@ -47,12 +47,12 @@ class Response(BaseModel):
|
|
|
47
47
|
def __init__(
|
|
48
48
|
self,
|
|
49
49
|
yaml_data: Dict[str, Any],
|
|
50
|
-
|
|
50
|
+
code_model: "CodeModel",
|
|
51
51
|
*,
|
|
52
52
|
headers: List[ResponseHeader] = [],
|
|
53
53
|
type: Optional[BaseType] = None,
|
|
54
54
|
) -> None:
|
|
55
|
-
super().__init__(yaml_data=yaml_data,
|
|
55
|
+
super().__init__(yaml_data=yaml_data, code_model=code_model)
|
|
56
56
|
self.status_codes: List[Union[int, str]] = yaml_data["statusCodes"]
|
|
57
57
|
self.headers = headers
|
|
58
58
|
self.type = type
|
|
@@ -115,21 +115,21 @@ class Response(BaseModel):
|
|
|
115
115
|
|
|
116
116
|
@classmethod
|
|
117
117
|
def from_yaml(
|
|
118
|
-
cls, yaml_data: Dict[str, Any],
|
|
118
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
119
119
|
) -> "Response":
|
|
120
120
|
type = (
|
|
121
|
-
|
|
121
|
+
code_model.lookup_type(id(yaml_data["type"]))
|
|
122
122
|
if yaml_data.get("type")
|
|
123
123
|
else None
|
|
124
124
|
)
|
|
125
125
|
# use ByteIteratorType if we are returning a binary type
|
|
126
126
|
if isinstance(type, BinaryType):
|
|
127
|
-
type = BinaryIteratorType(type.yaml_data, type.
|
|
127
|
+
type = BinaryIteratorType(type.yaml_data, type.code_model)
|
|
128
128
|
return cls(
|
|
129
129
|
yaml_data=yaml_data,
|
|
130
|
-
|
|
130
|
+
code_model=code_model,
|
|
131
131
|
headers=[
|
|
132
|
-
ResponseHeader.from_yaml(header,
|
|
132
|
+
ResponseHeader.from_yaml(header, code_model)
|
|
133
133
|
for header in yaml_data["headers"]
|
|
134
134
|
],
|
|
135
135
|
type=type,
|
|
@@ -142,9 +142,7 @@ class Response(BaseModel):
|
|
|
142
142
|
class PagingResponse(Response):
|
|
143
143
|
def __init__(self, *args, **kwargs) -> None:
|
|
144
144
|
super().__init__(*args, **kwargs)
|
|
145
|
-
self.item_type = self.
|
|
146
|
-
id(self.yaml_data["itemType"])
|
|
147
|
-
)
|
|
145
|
+
self.item_type = self.code_model.lookup_type(id(self.yaml_data["itemType"]))
|
|
148
146
|
|
|
149
147
|
def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
|
|
150
148
|
return self.item_type.get_polymorphic_subtypes(polymorphic_subtypes)
|
|
@@ -166,7 +164,7 @@ class PagingResponse(Response):
|
|
|
166
164
|
|
|
167
165
|
def docstring_text(self, **kwargs: Any) -> str:
|
|
168
166
|
base_description = "An iterator like instance of "
|
|
169
|
-
if not self.
|
|
167
|
+
if not self.code_model.options["version_tolerant"]:
|
|
170
168
|
base_description += "either "
|
|
171
169
|
return base_description + self.item_type.docstring_text(**kwargs)
|
|
172
170
|
|
|
@@ -247,7 +245,7 @@ class LROResponse(Response):
|
|
|
247
245
|
def docstring_text(self, **kwargs) -> str:
|
|
248
246
|
super_text = super().docstring_text(**kwargs)
|
|
249
247
|
base_description = f"An instance of {self.get_poller(kwargs.get('async_mode', False))} that returns "
|
|
250
|
-
if not self.
|
|
248
|
+
if not self.code_model.options["version_tolerant"]:
|
|
251
249
|
base_description += "either "
|
|
252
250
|
return base_description + super_text
|
|
253
251
|
|
|
@@ -310,7 +308,7 @@ class LROPagingResponse(LROResponse, PagingResponse):
|
|
|
310
308
|
base_description = (
|
|
311
309
|
"An instance of LROPoller that returns an iterator like instance of "
|
|
312
310
|
)
|
|
313
|
-
if not self.
|
|
311
|
+
if not self.code_model.options["version_tolerant"]:
|
|
314
312
|
base_description += "either "
|
|
315
313
|
return base_description + Response.docstring_text(self)
|
|
316
314
|
|
|
@@ -325,13 +323,11 @@ class LROPagingResponse(LROResponse, PagingResponse):
|
|
|
325
323
|
return file_import
|
|
326
324
|
|
|
327
325
|
|
|
328
|
-
def get_response(
|
|
329
|
-
yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
|
|
330
|
-
) -> Response:
|
|
326
|
+
def get_response(yaml_data: Dict[str, Any], code_model: "CodeModel") -> Response:
|
|
331
327
|
if yaml_data["discriminator"] == "lropaging":
|
|
332
|
-
return LROPagingResponse.from_yaml(yaml_data,
|
|
328
|
+
return LROPagingResponse.from_yaml(yaml_data, code_model)
|
|
333
329
|
if yaml_data["discriminator"] == "lro":
|
|
334
|
-
return LROResponse.from_yaml(yaml_data,
|
|
330
|
+
return LROResponse.from_yaml(yaml_data, code_model)
|
|
335
331
|
if yaml_data["discriminator"] == "paging":
|
|
336
|
-
return PagingResponse.from_yaml(yaml_data,
|
|
337
|
-
return Response.from_yaml(yaml_data,
|
|
332
|
+
return PagingResponse.from_yaml(yaml_data, code_model)
|
|
333
|
+
return Response.from_yaml(yaml_data, code_model)
|