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