@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
@@ -10,7 +10,7 @@ from .imports import FileImport
10
10
  from .utils import add_to_description
11
11
 
12
12
  if TYPE_CHECKING:
13
- from .code_model import CodeModel
13
+ from .code_model import NamespaceModel
14
14
 
15
15
  _LOGGER = logging.getLogger(__name__)
16
16
 
@@ -28,11 +28,11 @@ class ConstantType(BaseType):
28
28
  def __init__(
29
29
  self,
30
30
  yaml_data: Dict[str, Any],
31
- code_model: "CodeModel",
31
+ namespace_model: "NamespaceModel",
32
32
  value_type: BaseType,
33
33
  value: Optional[str],
34
34
  ) -> None:
35
- super().__init__(yaml_data=yaml_data, code_model=code_model)
35
+ super().__init__(yaml_data=yaml_data, namespace_model=namespace_model)
36
36
  self.value_type = value_type
37
37
  self.value = value
38
38
 
@@ -79,7 +79,7 @@ class ConstantType(BaseType):
79
79
 
80
80
  @classmethod
81
81
  def from_yaml(
82
- cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
82
+ cls, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
83
83
  ) -> "ConstantType":
84
84
  """Constructs a ConstantType from yaml data.
85
85
 
@@ -93,8 +93,8 @@ class ConstantType(BaseType):
93
93
 
94
94
  return cls(
95
95
  yaml_data=yaml_data,
96
- code_model=code_model,
97
- value_type=build_type(yaml_data["valueType"], code_model),
96
+ namespace_model=namespace_model,
97
+ value_type=build_type(yaml_data["valueType"], namespace_model),
98
98
  value=yaml_data["value"],
99
99
  )
100
100
 
@@ -20,7 +20,7 @@ from .imports import FileImport, ImportType, TypingSection
20
20
  from .base_type import BaseType
21
21
 
22
22
  if TYPE_CHECKING:
23
- from .code_model import CodeModel
23
+ from .code_model import NamespaceModel
24
24
 
25
25
 
26
26
  class _CredentialPolicyBaseType:
@@ -29,9 +29,11 @@ class _CredentialPolicyBaseType:
29
29
  Inherited by our BearerTokenCredentialPolicy and AzureKeyCredentialPolicy types.
30
30
  """
31
31
 
32
- def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
32
+ def __init__(
33
+ self, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
34
+ ) -> None:
33
35
  self.yaml_data = yaml_data
34
- self.code_model = code_model
36
+ self.namespace_model = namespace_model
35
37
 
36
38
  @abstractmethod
37
39
  def call(self, async_mode: bool) -> str:
@@ -47,10 +49,10 @@ class BearerTokenCredentialPolicyType(_CredentialPolicyBaseType):
47
49
  def __init__(
48
50
  self,
49
51
  yaml_data: Dict[str, Any],
50
- code_model: "CodeModel",
52
+ namespace_model: "NamespaceModel",
51
53
  credential_scopes: List[str],
52
54
  ) -> None:
53
- super().__init__(yaml_data, code_model)
55
+ super().__init__(yaml_data, namespace_model)
54
56
  self.credential_scopes = credential_scopes
55
57
 
56
58
  def call(self, async_mode: bool) -> str:
@@ -59,9 +61,9 @@ class BearerTokenCredentialPolicyType(_CredentialPolicyBaseType):
59
61
 
60
62
  @classmethod
61
63
  def from_yaml(
62
- cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
64
+ cls, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
63
65
  ) -> "BearerTokenCredentialPolicyType":
64
- return cls(yaml_data, code_model, yaml_data["credentialScopes"])
66
+ return cls(yaml_data, namespace_model, yaml_data["credentialScopes"])
65
67
 
66
68
 
67
69
  class ARMChallengeAuthenticationPolicyType(BearerTokenCredentialPolicyType):
@@ -74,9 +76,9 @@ class ARMChallengeAuthenticationPolicyType(BearerTokenCredentialPolicyType):
74
76
 
75
77
  class AzureKeyCredentialPolicyType(_CredentialPolicyBaseType):
76
78
  def __init__(
77
- self, yaml_data: Dict[str, Any], code_model: "CodeModel", key: str
79
+ self, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel", key: str
78
80
  ) -> None:
79
- super().__init__(yaml_data, code_model)
81
+ super().__init__(yaml_data, namespace_model)
80
82
  self.key = key
81
83
 
82
84
  def call(self, async_mode: bool) -> str:
@@ -84,9 +86,9 @@ class AzureKeyCredentialPolicyType(_CredentialPolicyBaseType):
84
86
 
85
87
  @classmethod
86
88
  def from_yaml(
87
- cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
89
+ cls, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
88
90
  ) -> "AzureKeyCredentialPolicyType":
89
- return cls(yaml_data, code_model, yaml_data["key"])
91
+ return cls(yaml_data, namespace_model, yaml_data["key"])
90
92
 
91
93
 
92
94
  CredentialPolicyType = TypeVar(
@@ -107,10 +109,10 @@ class CredentialType(
107
109
  def __init__(
108
110
  self,
109
111
  yaml_data: Dict[str, Any],
110
- code_model: "CodeModel",
112
+ namespace_model: "NamespaceModel",
111
113
  policy: CredentialPolicyType,
112
114
  ) -> None:
113
- super().__init__(yaml_data, code_model)
115
+ super().__init__(yaml_data, namespace_model)
114
116
  self.policy = policy
115
117
 
116
118
  def description(
@@ -138,15 +140,15 @@ class CredentialType(
138
140
 
139
141
  @classmethod
140
142
  def from_yaml(
141
- cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
143
+ cls, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
142
144
  ) -> "CredentialType":
143
145
  from . import build_type
144
146
 
145
147
  return cls(
146
148
  yaml_data,
147
- code_model,
149
+ namespace_model,
148
150
  policy=cast(
149
- CredentialPolicyType, build_type(yaml_data["policy"], code_model)
151
+ CredentialPolicyType, build_type(yaml_data["policy"], namespace_model)
150
152
  ),
151
153
  )
152
154
 
@@ -8,7 +8,7 @@ from .base_type import BaseType
8
8
  from .imports import FileImport, ImportType, TypingSection
9
9
 
10
10
  if TYPE_CHECKING:
11
- from .code_model import CodeModel
11
+ from .code_model import NamespaceModel
12
12
  from .model_type import ModelType
13
13
 
14
14
 
@@ -24,10 +24,10 @@ class DictionaryType(BaseType):
24
24
  def __init__(
25
25
  self,
26
26
  yaml_data: Dict[str, Any],
27
- code_model: "CodeModel",
27
+ namespace_model: "NamespaceModel",
28
28
  element_type: BaseType,
29
29
  ) -> None:
30
- super().__init__(yaml_data=yaml_data, code_model=code_model)
30
+ super().__init__(yaml_data=yaml_data, namespace_model=namespace_model)
31
31
  self.element_type = element_type
32
32
 
33
33
  @property
@@ -96,7 +96,7 @@ class DictionaryType(BaseType):
96
96
 
97
97
  @classmethod
98
98
  def from_yaml(
99
- cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
99
+ cls, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
100
100
  ) -> "DictionaryType":
101
101
  """Constructs a DictionaryType from yaml data.
102
102
 
@@ -110,11 +110,13 @@ class DictionaryType(BaseType):
110
110
 
111
111
  from . import build_type # pylint: disable=import-outside-toplevel
112
112
 
113
- element_type = build_type(yaml_data=element_schema, code_model=code_model)
113
+ element_type = build_type(
114
+ yaml_data=element_schema, namespace_model=namespace_model
115
+ )
114
116
 
115
117
  return cls(
116
118
  yaml_data=yaml_data,
117
- code_model=code_model,
119
+ namespace_model=namespace_model,
118
120
  element_type=element_type,
119
121
  )
120
122
 
@@ -10,7 +10,7 @@ from .imports import FileImport, ImportType, TypingSection
10
10
  from .base_model import BaseModel
11
11
 
12
12
  if TYPE_CHECKING:
13
- from .code_model import CodeModel
13
+ from .code_model import NamespaceModel
14
14
 
15
15
 
16
16
  class EnumValue(BaseModel):
@@ -21,15 +21,17 @@ class EnumValue(BaseModel):
21
21
  :param str description: Optional. The description for this enum value
22
22
  """
23
23
 
24
- def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
25
- super().__init__(yaml_data=yaml_data, code_model=code_model)
24
+ def __init__(
25
+ self, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
26
+ ) -> None:
27
+ super().__init__(yaml_data=yaml_data, namespace_model=namespace_model)
26
28
  self.name: str = self.yaml_data["name"]
27
29
  self.value: str = self.yaml_data["value"]
28
30
  self.description: Optional[str] = self.yaml_data.get("description")
29
31
 
30
32
  @classmethod
31
33
  def from_yaml(
32
- cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
34
+ cls, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
33
35
  ) -> "EnumValue":
34
36
  """Constructs an EnumValue from yaml data.
35
37
 
@@ -41,7 +43,7 @@ class EnumValue(BaseModel):
41
43
  """
42
44
  return cls(
43
45
  yaml_data=yaml_data,
44
- code_model=code_model,
46
+ namespace_model=namespace_model,
45
47
  )
46
48
 
47
49
 
@@ -60,11 +62,11 @@ class EnumType(BaseType):
60
62
  def __init__(
61
63
  self,
62
64
  yaml_data: Dict[str, Any],
63
- code_model: "CodeModel",
65
+ namespace_model: "NamespaceModel",
64
66
  values: List["EnumValue"],
65
67
  value_type: BaseType,
66
68
  ) -> None:
67
- super().__init__(yaml_data=yaml_data, code_model=code_model)
69
+ super().__init__(yaml_data=yaml_data, namespace_model=namespace_model)
68
70
  self.name: str = yaml_data["name"]
69
71
  self.values = values
70
72
  self.value_type = value_type
@@ -106,7 +108,7 @@ class EnumType(BaseType):
106
108
  :return: The type annotation for this schema
107
109
  :rtype: str
108
110
  """
109
- if self.code_model.options["models_mode"]:
111
+ if self.namespace_model.options["models_mode"]:
110
112
  model_name = f"_models.{self.name}"
111
113
  # we don't need quoted annotation in operation files, and need it in model folder files.
112
114
  if not kwargs.get("is_operation_file", False):
@@ -119,14 +121,18 @@ class EnumType(BaseType):
119
121
  return self.value_type.get_declaration(value)
120
122
 
121
123
  def docstring_text(self, **kwargs: Any) -> str:
122
- if self.code_model.options["models_mode"]:
124
+ if self.namespace_model.options["models_mode"]:
123
125
  return self.name
124
126
  return self.value_type.type_annotation(**kwargs)
125
127
 
126
128
  def docstring_type(self, **kwargs: Any) -> str:
127
129
  """The python type used for RST syntax input and type annotation."""
128
- if self.code_model.options["models_mode"]:
129
- return f"{self.value_type.type_annotation(**kwargs)} or ~{self.code_model.namespace}.models.{self.name}"
130
+ if self.namespace_model.options["models_mode"]:
131
+ type_annotation = self.value_type.type_annotation(**kwargs)
132
+ enum_type_annotation = (
133
+ f"{self.namespace_model.namespace}.models.{self.name}"
134
+ )
135
+ return f"{type_annotation} or ~{enum_type_annotation}"
130
136
  return self.value_type.type_annotation(**kwargs)
131
137
 
132
138
  def get_json_template_representation(
@@ -149,7 +155,7 @@ class EnumType(BaseType):
149
155
 
150
156
  @classmethod
151
157
  def from_yaml(
152
- cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
158
+ cls, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
153
159
  ) -> "EnumType":
154
160
  """Constructs an EnumType from yaml data.
155
161
 
@@ -163,17 +169,18 @@ class EnumType(BaseType):
163
169
 
164
170
  return cls(
165
171
  yaml_data=yaml_data,
166
- code_model=code_model,
167
- value_type=build_type(yaml_data["valueType"], code_model),
172
+ namespace_model=namespace_model,
173
+ value_type=build_type(yaml_data["valueType"], namespace_model),
168
174
  values=[
169
- EnumValue.from_yaml(value, code_model) for value in yaml_data["values"]
175
+ EnumValue.from_yaml(value, namespace_model)
176
+ for value in yaml_data["values"]
170
177
  ],
171
178
  )
172
179
 
173
180
  def imports(self, **kwargs: Any) -> FileImport:
174
181
  is_operation_file = kwargs.pop("is_operation_file", False)
175
182
  file_import = FileImport()
176
- if self.code_model.options["models_mode"]:
183
+ if self.namespace_model.options["models_mode"]:
177
184
  file_import.add_submodule_import(
178
185
  "typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL
179
186
  )
@@ -189,7 +196,7 @@ class EnumType(BaseType):
189
196
  self.value_type.imports(is_operation_file=is_operation_file, **kwargs)
190
197
  )
191
198
  relative_path = kwargs.pop("relative_path", None)
192
- if self.code_model.options["models_mode"] and relative_path:
199
+ if self.namespace_model.options["models_mode"] and relative_path:
193
200
  # add import for enums in operations file
194
201
  file_import.add_submodule_import(
195
202
  relative_path, "models", ImportType.LOCAL, alias="_models"
@@ -7,7 +7,7 @@ from enum import Enum, auto
7
7
  from typing import Dict, List, Optional, Tuple, Union, Set, Mapping, TYPE_CHECKING
8
8
 
9
9
  if TYPE_CHECKING:
10
- from .code_model import CodeModel
10
+ from .code_model import NamespaceModel
11
11
 
12
12
 
13
13
  class ImportType(str, Enum):
@@ -206,12 +206,12 @@ class FileImport:
206
206
 
207
207
  def add_msrest_import(
208
208
  self,
209
- code_model: "CodeModel",
209
+ namespace_model: "NamespaceModel",
210
210
  relative_path: str,
211
211
  msrest_import_type: MsrestImportType,
212
212
  typing_section: TypingSection,
213
213
  ):
214
- if code_model.options["client_side_validation"]:
214
+ if namespace_model.options["client_side_validation"]:
215
215
  if msrest_import_type == MsrestImportType.Module:
216
216
  self.add_import(
217
217
  "msrest.serialization", ImportType.AZURECORE, typing_section
@@ -225,7 +225,7 @@ class FileImport:
225
225
  "msrest", "Deserializer", ImportType.THIRDPARTY, typing_section
226
226
  )
227
227
  else:
228
- if code_model.options["multiapi"]:
228
+ if namespace_model.options["multiapi"]:
229
229
  relative_path += "."
230
230
  if msrest_import_type == MsrestImportType.Module:
231
231
  self.add_submodule_import(
@@ -8,7 +8,7 @@ from .base_type import BaseType
8
8
  from .imports import FileImport, ImportType, TypingSection
9
9
 
10
10
  if TYPE_CHECKING:
11
- from .code_model import CodeModel
11
+ from .code_model import NamespaceModel
12
12
  from .model_type import ModelType
13
13
 
14
14
 
@@ -16,10 +16,10 @@ class ListType(BaseType):
16
16
  def __init__(
17
17
  self,
18
18
  yaml_data: Dict[str, Any],
19
- code_model: "CodeModel",
19
+ namespace_model: "NamespaceModel",
20
20
  element_type: BaseType,
21
21
  ) -> None:
22
- super().__init__(yaml_data=yaml_data, code_model=code_model)
22
+ super().__init__(yaml_data=yaml_data, namespace_model=namespace_model)
23
23
  self.element_type = element_type
24
24
  self.max_items: Optional[int] = yaml_data.get("maxItems")
25
25
  self.min_items: Optional[int] = yaml_data.get("minItems")
@@ -30,7 +30,10 @@ class ListType(BaseType):
30
30
  return f"[{self.element_type.serialization_type}]"
31
31
 
32
32
  def type_annotation(self, **kwargs: Any) -> str:
33
- if self.code_model.options["version_tolerant"] and self.element_type.is_xml:
33
+ if (
34
+ self.namespace_model.options["version_tolerant"]
35
+ and self.element_type.is_xml
36
+ ):
34
37
  # this means we're version tolerant XML, we just return the XML element
35
38
  return self.element_type.type_annotation(**kwargs)
36
39
  return f"List[{self.element_type.type_annotation(**kwargs)}]"
@@ -62,7 +65,7 @@ class ListType(BaseType):
62
65
 
63
66
  def docstring_type(self, **kwargs: Any) -> str:
64
67
  if (
65
- self.code_model.options["version_tolerant"]
68
+ self.namespace_model.options["version_tolerant"]
66
69
  and self.element_type.xml_metadata
67
70
  ):
68
71
  # this means we're version tolerant XML, we just return the XML element
@@ -71,7 +74,7 @@ class ListType(BaseType):
71
74
 
72
75
  def docstring_text(self, **kwargs: Any) -> str:
73
76
  if (
74
- self.code_model.options["version_tolerant"]
77
+ self.namespace_model.options["version_tolerant"]
75
78
  and self.element_type.xml_metadata
76
79
  ):
77
80
  # this means we're version tolerant XML, we just return the XML element
@@ -125,22 +128,23 @@ class ListType(BaseType):
125
128
 
126
129
  @classmethod
127
130
  def from_yaml(
128
- cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
131
+ cls, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
129
132
  ) -> "ListType":
130
133
  from . import build_type
131
134
 
132
135
  return cls(
133
136
  yaml_data=yaml_data,
134
- code_model=code_model,
137
+ namespace_model=namespace_model,
135
138
  element_type=build_type(
136
- yaml_data=yaml_data["elementType"], code_model=code_model
139
+ yaml_data=yaml_data["elementType"], namespace_model=namespace_model
137
140
  ),
138
141
  )
139
142
 
140
143
  def imports(self, **kwargs: Any) -> FileImport:
141
144
  file_import = FileImport()
142
145
  if not (
143
- self.code_model.options["version_tolerant"] and self.element_type.is_xml
146
+ self.namespace_model.options["version_tolerant"]
147
+ and self.element_type.is_xml
144
148
  ):
145
149
  file_import.add_submodule_import(
146
150
  "typing", "List", ImportType.STDLIB, TypingSection.CONDITIONAL
@@ -12,7 +12,8 @@ from .request_builder import RequestBuilder
12
12
  from .parameter_list import ParameterList
13
13
 
14
14
  if TYPE_CHECKING:
15
- from .code_model import CodeModel
15
+ from .code_model import NamespaceModel
16
+ from .client import Client
16
17
 
17
18
  LROResponseType = TypeVar(
18
19
  "LROResponseType", bound=Union[LROResponse, LROPagingResponse]
@@ -23,7 +24,8 @@ class LROOperationBase(OperationBase[LROResponseType]):
23
24
  def __init__(
24
25
  self,
25
26
  yaml_data: Dict[str, Any],
26
- code_model: "CodeModel",
27
+ namespace_model: "NamespaceModel",
28
+ client: "Client",
27
29
  name: str,
28
30
  request_builder: RequestBuilder,
29
31
  parameters: ParameterList,
@@ -35,7 +37,8 @@ class LROOperationBase(OperationBase[LROResponseType]):
35
37
  want_tracing: bool = True,
36
38
  ) -> None:
37
39
  super().__init__(
38
- code_model=code_model,
40
+ namespace_model=namespace_model,
41
+ client=client,
39
42
  yaml_data=yaml_data,
40
43
  name=name,
41
44
  request_builder=request_builder,
@@ -89,13 +92,18 @@ class LROOperationBase(OperationBase[LROResponseType]):
89
92
  """Initial operation that creates the first call for LRO polling"""
90
93
  return Operation(
91
94
  yaml_data=self.yaml_data,
92
- code_model=self.code_model,
93
- request_builder=self.code_model.lookup_request_builder(id(self.yaml_data)),
95
+ namespace_model=self.namespace_model,
96
+ client=self.client,
97
+ request_builder=self.namespace_model.lookup_request_builder(
98
+ id(self.yaml_data)
99
+ ),
94
100
  name=self.name[5:] + "_initial",
95
101
  overloads=self.overloads,
96
102
  parameters=self.parameters,
97
103
  responses=[
98
- Response(r.yaml_data, self.code_model, headers=r.headers, type=r.type)
104
+ Response(
105
+ r.yaml_data, self.namespace_model, headers=r.headers, type=r.type
106
+ )
99
107
  for r in self.responses
100
108
  ],
101
109
  exceptions=self.exceptions,
@@ -13,7 +13,7 @@ from .property import Property
13
13
  from .imports import FileImport, ImportType, TypingSection
14
14
 
15
15
  if TYPE_CHECKING:
16
- from .code_model import CodeModel
16
+ from .code_model import NamespaceModel
17
17
 
18
18
 
19
19
  def _get_properties(type: "ModelType", properties: List[Property]) -> List[Property]:
@@ -47,13 +47,13 @@ class ModelType(
47
47
  def __init__(
48
48
  self,
49
49
  yaml_data: Dict[str, Any],
50
- code_model: "CodeModel",
50
+ namespace_model: "NamespaceModel",
51
51
  *,
52
52
  properties: Optional[List[Property]] = None,
53
53
  parents: Optional[List["ModelType"]] = None,
54
54
  discriminated_subtypes: Optional[Dict[str, "ModelType"]] = None,
55
55
  ) -> None:
56
- super().__init__(yaml_data=yaml_data, code_model=code_model)
56
+ super().__init__(yaml_data=yaml_data, namespace_model=namespace_model)
57
57
  self.name: str = self.yaml_data["name"]
58
58
  self.max_properties: Optional[int] = self.yaml_data.get("maxProperties")
59
59
  self.min_properties: Optional[int] = self.yaml_data.get("minProperties")
@@ -74,10 +74,10 @@ class ModelType(
74
74
 
75
75
  @property
76
76
  def serialization_type(self) -> str:
77
- if self.code_model.options["models_mode"] == "msrest":
78
- private_model_path = f"_models.{self.code_model.models_filename}."
77
+ if self.namespace_model.options["models_mode"] == "msrest":
78
+ private_model_path = f"_models.{self.namespace_model.models_filename}."
79
79
  return f"{'' if self.is_public else private_model_path}{self.name}"
80
- if self.code_model.options["models_mode"] == "dpg":
80
+ if self.namespace_model.options["models_mode"] == "dpg":
81
81
  return f"{'' if self.is_public else '_models.'}_models.{self.name}"
82
82
  return "object"
83
83
 
@@ -86,24 +86,24 @@ class ModelType(
86
86
  return any(p.is_polymorphic for p in self.properties)
87
87
 
88
88
  def type_annotation(self, **kwargs: Any) -> str:
89
- if self.code_model.options["models_mode"]:
89
+ if self.namespace_model.options["models_mode"]:
90
90
  is_operation_file = kwargs.pop("is_operation_file", False)
91
91
  retval = f"_models.{self.name}"
92
92
  if not self.is_public:
93
- retval = f"{self.code_model.models_filename}.{retval}"
93
+ retval = f"{self.namespace_model.models_filename}.{retval}"
94
94
  return retval if is_operation_file else f'"{retval}"'
95
95
  return "ET.Element" if self.is_xml else "JSON"
96
96
 
97
97
  def docstring_type(self, **kwargs: Any) -> str:
98
- if self.code_model.options["models_mode"]:
99
- return f"~{self.code_model.namespace}.models.{self.name}"
98
+ if self.namespace_model.options["models_mode"]:
99
+ return f"~{self.namespace_model.namespace}.models.{self.name}"
100
100
  return "ET.Element" if self.is_xml else "JSON"
101
101
 
102
102
  def description(self, *, is_operation_file: bool = False) -> str:
103
103
  return "" if is_operation_file else self.yaml_data.get("description", self.name)
104
104
 
105
105
  def docstring_text(self, **kwargs: Any) -> str:
106
- if self.code_model.options["models_mode"]:
106
+ if self.namespace_model.options["models_mode"]:
107
107
  return self.name
108
108
  return "XML Element" if self.is_xml else "JSON object"
109
109
 
@@ -198,7 +198,7 @@ class ModelType(
198
198
 
199
199
  @classmethod
200
200
  def from_yaml(
201
- cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
201
+ cls, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
202
202
  ) -> "ModelType":
203
203
  raise ValueError(
204
204
  "You shouldn't call from_yaml for ModelType to avoid recursion. "
@@ -206,21 +206,21 @@ class ModelType(
206
206
  )
207
207
 
208
208
  def fill_instance_from_yaml(
209
- self, yaml_data: Dict[str, Any], code_model: "CodeModel"
209
+ self, yaml_data: Dict[str, Any], namespace_model: "NamespaceModel"
210
210
  ) -> None:
211
211
  from . import build_type
212
212
 
213
213
  self.parents = [
214
- cast(ModelType, build_type(bm, code_model))
214
+ cast(ModelType, build_type(bm, namespace_model))
215
215
  for bm in yaml_data.get("parents", [])
216
216
  ]
217
217
  properties = [
218
- Property.from_yaml(p, code_model) for p in yaml_data["properties"]
218
+ Property.from_yaml(p, namespace_model) for p in yaml_data["properties"]
219
219
  ]
220
220
  self.properties = _get_properties(self, properties)
221
221
  # checking to see if this is a polymorphic class
222
222
  self.discriminated_subtypes = {
223
- k: cast(ModelType, build_type(v, code_model))
223
+ k: cast(ModelType, build_type(v, namespace_model))
224
224
  for k, v in self.yaml_data.get("discriminatedSubtypes", {}).items()
225
225
  }
226
226
 
@@ -250,7 +250,7 @@ class ModelType(
250
250
 
251
251
  @property
252
252
  def instance_check_template(self) -> str:
253
- models_mode = self.code_model.options["models_mode"]
253
+ models_mode = self.namespace_model.options["models_mode"]
254
254
  if models_mode == "msrest":
255
255
  return "isinstance({}, msrest.Model)"
256
256
  if models_mode == "dpg":
@@ -274,12 +274,12 @@ class ModelType(
274
274
  def imports(self, **kwargs: Any) -> FileImport:
275
275
  file_import = FileImport()
276
276
  relative_path = kwargs.pop("relative_path", None)
277
- if self.code_model.options["models_mode"] and relative_path:
277
+ if self.namespace_model.options["models_mode"] and relative_path:
278
278
  # add import for models in operations file
279
279
  file_import.add_submodule_import(
280
280
  relative_path, "models", ImportType.LOCAL, alias="_models"
281
281
  )
282
- if self.code_model.options["models_mode"] == "msrest":
282
+ if self.namespace_model.options["models_mode"] == "msrest":
283
283
  return file_import
284
284
  file_import.add_submodule_import(
285
285
  "typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL