@typespec/http-client-python 0.13.0-dev.2 → 0.13.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/eng/scripts/setup/__pycache__/package_manager.cpython-39.pyc +0 -0
- package/eng/scripts/setup/__pycache__/venvtools.cpython-39.pyc +0 -0
- package/eng/scripts/setup/build_pygen_wheel.py +1 -0
- package/eng/scripts/setup/install.py +4 -2
- package/eng/scripts/setup/package_manager.py +24 -22
- package/eng/scripts/setup/prepare.py +1 -1
- package/eng/scripts/setup/venvtools.py +1 -3
- package/generator/build/lib/pygen/__init__.py +176 -2
- package/generator/build/lib/pygen/black.py +1 -1
- package/generator/build/lib/pygen/codegen/__init__.py +4 -256
- package/generator/build/lib/pygen/codegen/_utils.py +0 -3
- package/generator/build/lib/pygen/codegen/models/__init__.py +1 -1
- package/generator/build/lib/pygen/codegen/models/base_builder.py +1 -1
- package/generator/build/lib/pygen/codegen/models/client.py +15 -13
- package/generator/build/lib/pygen/codegen/models/code_model.py +10 -9
- package/generator/build/lib/pygen/codegen/models/enum_type.py +4 -4
- package/generator/build/lib/pygen/codegen/models/imports.py +1 -1
- package/generator/build/lib/pygen/codegen/models/list_type.py +6 -6
- package/generator/build/lib/pygen/codegen/models/lro_operation.py +1 -1
- package/generator/build/lib/pygen/codegen/models/operation.py +16 -16
- package/generator/build/lib/pygen/codegen/models/operation_group.py +12 -6
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +4 -4
- package/generator/build/lib/pygen/codegen/models/parameter.py +8 -8
- package/generator/build/lib/pygen/codegen/models/property.py +1 -1
- package/generator/build/lib/pygen/codegen/models/request_builder.py +2 -2
- package/generator/build/lib/pygen/codegen/models/request_builder_parameter.py +2 -2
- package/generator/build/lib/pygen/codegen/models/response.py +3 -3
- package/generator/build/lib/pygen/codegen/serializers/__init__.py +27 -28
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +31 -31
- package/generator/build/lib/pygen/codegen/serializers/client_serializer.py +6 -5
- package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +4 -4
- package/generator/build/lib/pygen/codegen/serializers/metadata_serializer.py +1 -1
- package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +1 -1
- package/generator/build/lib/pygen/codegen/serializers/operations_init_serializer.py +6 -2
- package/generator/build/lib/pygen/codegen/serializers/sample_serializer.py +1 -1
- package/generator/build/lib/pygen/codegen/serializers/test_serializer.py +5 -5
- package/generator/build/lib/pygen/codegen/templates/config.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/config_container.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/conftest.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/init.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/metadata.json.jinja2 +2 -2
- package/generator/build/lib/pygen/codegen/templates/model_dpg.py.jinja2 +2 -2
- package/generator/build/lib/pygen/codegen/templates/operation_group.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/operation_groups_container.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/operation_tools.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/operations_folder_init.py.jinja2 +2 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/README.md.jinja2 +38 -7
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +9 -9
- package/generator/build/lib/pygen/codegen/templates/request_builder.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/sample.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/test.py.jinja2 +6 -6
- package/generator/build/lib/pygen/codegen/templates/version.py.jinja2 +1 -1
- package/generator/build/lib/pygen/preprocess/__init__.py +1 -1
- package/generator/build/lib/pygen/utils.py +4 -0
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/__init__.py +176 -2
- package/generator/pygen/black.py +1 -1
- package/generator/pygen/codegen/__init__.py +4 -256
- package/generator/pygen/codegen/_utils.py +0 -3
- package/generator/pygen/codegen/models/__init__.py +1 -1
- package/generator/pygen/codegen/models/base_builder.py +1 -1
- package/generator/pygen/codegen/models/client.py +15 -13
- package/generator/pygen/codegen/models/code_model.py +10 -9
- package/generator/pygen/codegen/models/enum_type.py +4 -4
- package/generator/pygen/codegen/models/imports.py +1 -1
- package/generator/pygen/codegen/models/list_type.py +6 -6
- package/generator/pygen/codegen/models/lro_operation.py +1 -1
- package/generator/pygen/codegen/models/operation.py +16 -16
- package/generator/pygen/codegen/models/operation_group.py +12 -6
- package/generator/pygen/codegen/models/paging_operation.py +4 -4
- package/generator/pygen/codegen/models/parameter.py +8 -8
- package/generator/pygen/codegen/models/property.py +1 -1
- package/generator/pygen/codegen/models/request_builder.py +2 -2
- package/generator/pygen/codegen/models/request_builder_parameter.py +2 -2
- package/generator/pygen/codegen/models/response.py +3 -3
- package/generator/pygen/codegen/serializers/__init__.py +27 -28
- package/generator/pygen/codegen/serializers/builder_serializer.py +31 -31
- package/generator/pygen/codegen/serializers/client_serializer.py +6 -5
- package/generator/pygen/codegen/serializers/general_serializer.py +4 -4
- package/generator/pygen/codegen/serializers/metadata_serializer.py +1 -1
- package/generator/pygen/codegen/serializers/model_serializer.py +1 -1
- package/generator/pygen/codegen/serializers/operations_init_serializer.py +6 -2
- package/generator/pygen/codegen/serializers/sample_serializer.py +1 -1
- package/generator/pygen/codegen/serializers/test_serializer.py +5 -5
- package/generator/pygen/codegen/templates/config.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/config_container.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/conftest.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/init.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/metadata.json.jinja2 +2 -2
- package/generator/pygen/codegen/templates/model_dpg.py.jinja2 +2 -2
- package/generator/pygen/codegen/templates/operation_group.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/operation_groups_container.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/operation_tools.jinja2 +1 -1
- package/generator/pygen/codegen/templates/operations_folder_init.py.jinja2 +2 -0
- package/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 +1 -1
- package/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 +38 -7
- package/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +1 -1
- package/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +9 -9
- package/generator/pygen/codegen/templates/request_builder.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/sample.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/test.py.jinja2 +6 -6
- package/generator/pygen/codegen/templates/version.py.jinja2 +1 -1
- package/generator/pygen/preprocess/__init__.py +1 -1
- package/generator/pygen/utils.py +4 -0
- package/generator/test/unittests/test_optional_return_type.py +5 -5
- package/generator/test/unittests/test_parameter_ordering.py +5 -5
- package/generator/test/unittests/test_sort_schema.py +4 -4
- package/package.json +1 -1
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
|
-
from typing import Dict, Any
|
|
8
|
-
from pathlib import Path
|
|
7
|
+
from typing import Dict, Any
|
|
9
8
|
import yaml
|
|
10
9
|
|
|
11
10
|
|
|
@@ -13,223 +12,12 @@ from .. import Plugin
|
|
|
13
12
|
from ..utils import parse_args
|
|
14
13
|
from .models.code_model import CodeModel
|
|
15
14
|
from .serializers import JinjaSerializer
|
|
16
|
-
from ._utils import VALID_PACKAGE_MODE, TYPESPEC_PACKAGE_MODE
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def _default_pprint(package_name: str) -> str:
|
|
20
|
-
return " ".join([i.capitalize() for i in package_name.split("-")])
|
|
21
15
|
|
|
22
16
|
|
|
23
17
|
_LOGGER = logging.getLogger(__name__)
|
|
24
18
|
|
|
25
19
|
|
|
26
|
-
class OptionsRetriever:
|
|
27
|
-
OPTIONS_TO_DEFAULT = {
|
|
28
|
-
"azure-arm": False,
|
|
29
|
-
"flavor": "azure", # need to default to azure in shared code so we don't break swagger generation
|
|
30
|
-
"no-async": False,
|
|
31
|
-
"low-level-client": False,
|
|
32
|
-
"version-tolerant": True,
|
|
33
|
-
"keep-version-file": False,
|
|
34
|
-
"no-namespace-folders": False,
|
|
35
|
-
"basic-setup-py": False,
|
|
36
|
-
"client-side-validation": False,
|
|
37
|
-
"multiapi": False,
|
|
38
|
-
"polymorphic-examples": 5,
|
|
39
|
-
"generate-sample": False,
|
|
40
|
-
"generate-test": False,
|
|
41
|
-
"from-typespec": False,
|
|
42
|
-
"emit-cross-language-definition-file": False,
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@property
|
|
46
|
-
def is_azure_flavor(self) -> bool:
|
|
47
|
-
return self.flavor == "azure"
|
|
48
|
-
|
|
49
|
-
def __init__(self, options: Dict[str, Any]) -> None:
|
|
50
|
-
self.options = options
|
|
51
|
-
|
|
52
|
-
def __getattr__(self, prop: str) -> Any:
|
|
53
|
-
key = prop.replace("_", "-")
|
|
54
|
-
return self.options.get(key, self.OPTIONS_TO_DEFAULT.get(key))
|
|
55
|
-
|
|
56
|
-
@property
|
|
57
|
-
def show_operations(self) -> bool:
|
|
58
|
-
return self.options.get("show-operations", not self.low_level_client)
|
|
59
|
-
|
|
60
|
-
@property
|
|
61
|
-
def _models_mode_default(self) -> str:
|
|
62
|
-
models_mode_default = "none" if self.low_level_client or self.version_tolerant else "msrest"
|
|
63
|
-
if self.options.get("tsp_file") is not None:
|
|
64
|
-
models_mode_default = "dpg"
|
|
65
|
-
return models_mode_default
|
|
66
|
-
|
|
67
|
-
@property
|
|
68
|
-
def original_models_mode(self) -> str:
|
|
69
|
-
return self.options.get("models-mode", self._models_mode_default)
|
|
70
|
-
|
|
71
|
-
@property
|
|
72
|
-
def models_mode(self) -> Union[str, bool]:
|
|
73
|
-
# switch to falsy value for easier code writing
|
|
74
|
-
return False if self.original_models_mode == "none" else self.original_models_mode
|
|
75
|
-
|
|
76
|
-
@property
|
|
77
|
-
def tracing(self) -> bool:
|
|
78
|
-
return self.options.get(
|
|
79
|
-
"tracing",
|
|
80
|
-
self.show_operations and self.is_azure_flavor,
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
@property
|
|
84
|
-
def show_send_request(self) -> bool:
|
|
85
|
-
return self.options.get(
|
|
86
|
-
"show-send-request",
|
|
87
|
-
self._low_level_or_version_tolerant,
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
@property
|
|
91
|
-
def _low_level_or_version_tolerant(self) -> bool:
|
|
92
|
-
return self.low_level_client or self.version_tolerant
|
|
93
|
-
|
|
94
|
-
@property
|
|
95
|
-
def only_path_and_body_params_positional(self) -> bool:
|
|
96
|
-
return self.options.get(
|
|
97
|
-
"only-path-and-body-params-positional",
|
|
98
|
-
self._low_level_or_version_tolerant,
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
@property
|
|
102
|
-
def combine_operation_files(self) -> bool:
|
|
103
|
-
return self.options.get(
|
|
104
|
-
"combine-operation-files",
|
|
105
|
-
self.version_tolerant,
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
@property
|
|
109
|
-
def package_pprint_name(self) -> str:
|
|
110
|
-
return self.options.get("package-pprint-name") or _default_pprint(str(self.package_name))
|
|
111
|
-
|
|
112
|
-
@property
|
|
113
|
-
def validate_versioning(self) -> bool:
|
|
114
|
-
return self.options.get("validate-versioning", True)
|
|
115
|
-
|
|
116
|
-
@property
|
|
117
|
-
def default_optional_constants_to_none(self) -> bool:
|
|
118
|
-
return self.options.get(
|
|
119
|
-
"default-optional-constants-to-none",
|
|
120
|
-
self._low_level_or_version_tolerant,
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
@property
|
|
124
|
-
def builders_visibility(self) -> str:
|
|
125
|
-
builders_visibility = self.options.get("builders-visibility")
|
|
126
|
-
if builders_visibility is None:
|
|
127
|
-
return "public" if self.low_level_client else "embedded"
|
|
128
|
-
return builders_visibility.lower()
|
|
129
|
-
|
|
130
|
-
@property
|
|
131
|
-
def head_as_boolean(self) -> bool:
|
|
132
|
-
head_as_boolean = self.options.get("head-as-boolean", True)
|
|
133
|
-
# Force some options in ARM MODE
|
|
134
|
-
return True if self.azure_arm else head_as_boolean
|
|
135
|
-
|
|
136
|
-
@property
|
|
137
|
-
def package_mode(self) -> str:
|
|
138
|
-
return self.options.get("packaging-files-dir") or self.options.get("package-mode", "")
|
|
139
|
-
|
|
140
|
-
@property
|
|
141
|
-
def packaging_files_config(self) -> Optional[Dict[str, Any]]:
|
|
142
|
-
packaging_files_config = self.options.get("packaging-files-config")
|
|
143
|
-
if packaging_files_config is None:
|
|
144
|
-
return None
|
|
145
|
-
# packaging-files-config is either a string or a dict
|
|
146
|
-
# if it's a string, we can split on the comma to get the dict
|
|
147
|
-
# otherwise we just return
|
|
148
|
-
try:
|
|
149
|
-
return {k.strip(): v.strip() for k, v in [i.split(":") for i in packaging_files_config.split("|")]}
|
|
150
|
-
except AttributeError:
|
|
151
|
-
return packaging_files_config
|
|
152
|
-
|
|
153
|
-
@property
|
|
154
|
-
def package_version(self) -> Optional[str]:
|
|
155
|
-
return str(self.options.get("package-version", ""))
|
|
156
|
-
|
|
157
|
-
@property
|
|
158
|
-
def header_text(self) -> Optional[str]:
|
|
159
|
-
return self.options.get("header-text")
|
|
160
|
-
|
|
161
|
-
|
|
162
20
|
class CodeGenerator(Plugin):
|
|
163
|
-
def __init__(self, *args, **kwargs: Any) -> None:
|
|
164
|
-
super().__init__(*args, **kwargs)
|
|
165
|
-
self.options_retriever = OptionsRetriever(self.options)
|
|
166
|
-
|
|
167
|
-
def _validate_code_model_options(self) -> None:
|
|
168
|
-
if self.options_retriever.builders_visibility not in [
|
|
169
|
-
"public",
|
|
170
|
-
"hidden",
|
|
171
|
-
"embedded",
|
|
172
|
-
]:
|
|
173
|
-
raise ValueError("The value of --builders-visibility must be either 'public', 'hidden', or 'embedded'")
|
|
174
|
-
|
|
175
|
-
if self.options_retriever.original_models_mode not in ["msrest", "dpg", "none"]:
|
|
176
|
-
raise ValueError(
|
|
177
|
-
"--models-mode can only be 'msrest', 'dpg' or 'none'. "
|
|
178
|
-
"Pass in 'msrest' if you want msrest models, or "
|
|
179
|
-
"'none' if you don't want any."
|
|
180
|
-
)
|
|
181
|
-
|
|
182
|
-
if not self.options_retriever.show_operations and self.options_retriever.builders_visibility == "embedded":
|
|
183
|
-
raise ValueError(
|
|
184
|
-
"Can not embed builders without operations. "
|
|
185
|
-
"Either set --show-operations to True, or change the value of --builders-visibility "
|
|
186
|
-
"to 'public' or 'hidden'."
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
-
if self.options_retriever.basic_setup_py and not self.options_retriever.package_version:
|
|
190
|
-
raise ValueError("--basic-setup-py must be used with --package-version")
|
|
191
|
-
|
|
192
|
-
if self.options_retriever.package_mode and not self.options_retriever.package_version:
|
|
193
|
-
raise ValueError("--package-mode must be used with --package-version")
|
|
194
|
-
|
|
195
|
-
if not self.options_retriever.show_operations and self.options_retriever.combine_operation_files:
|
|
196
|
-
raise ValueError(
|
|
197
|
-
"Can not combine operation files if you are not showing operations. "
|
|
198
|
-
"If you want operation files, pass in flag --show-operations"
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
if self.options_retriever.package_mode:
|
|
202
|
-
if (
|
|
203
|
-
(
|
|
204
|
-
self.options_retriever.package_mode not in TYPESPEC_PACKAGE_MODE
|
|
205
|
-
and self.options_retriever.from_typespec
|
|
206
|
-
)
|
|
207
|
-
or (
|
|
208
|
-
self.options_retriever.package_mode not in VALID_PACKAGE_MODE
|
|
209
|
-
and not self.options_retriever.from_typespec
|
|
210
|
-
)
|
|
211
|
-
) and not Path(self.options_retriever.package_mode).exists():
|
|
212
|
-
raise ValueError(
|
|
213
|
-
f"--package-mode can only be {' or '.join(TYPESPEC_PACKAGE_MODE)} or directory which contains template files" # pylint: disable=line-too-long
|
|
214
|
-
)
|
|
215
|
-
|
|
216
|
-
if self.options_retriever.multiapi and self.options_retriever.version_tolerant:
|
|
217
|
-
raise ValueError(
|
|
218
|
-
"Can not currently generate version tolerant multiapi SDKs. "
|
|
219
|
-
"We are working on creating a new multiapi SDK for version tolerant and it is not available yet."
|
|
220
|
-
)
|
|
221
|
-
|
|
222
|
-
if self.options_retriever.client_side_validation and self.options_retriever.version_tolerant:
|
|
223
|
-
raise ValueError("Can not generate version tolerant with --client-side-validation. ")
|
|
224
|
-
|
|
225
|
-
if not (self.options_retriever.azure_arm or self.options_retriever.version_tolerant):
|
|
226
|
-
_LOGGER.warning(
|
|
227
|
-
"You are generating with options that would not allow the SDK to be shipped as an official Azure SDK. "
|
|
228
|
-
"Please read https://aka.ms/azsdk/dpcodegen for more details."
|
|
229
|
-
)
|
|
230
|
-
|
|
231
|
-
if not self.options_retriever.is_azure_flavor and self.options_retriever.tracing:
|
|
232
|
-
raise ValueError("Can only have tracing turned on for Azure SDKs.")
|
|
233
21
|
|
|
234
22
|
@staticmethod
|
|
235
23
|
def sort_exceptions(yaml_data: Dict[str, Any]) -> None:
|
|
@@ -272,43 +60,6 @@ class CodeGenerator(Plugin):
|
|
|
272
60
|
del yaml_data["schemas"]["objects"][i]
|
|
273
61
|
break
|
|
274
62
|
|
|
275
|
-
def _build_code_model_options(self) -> Dict[str, Any]:
|
|
276
|
-
flags = [
|
|
277
|
-
"azure_arm",
|
|
278
|
-
"head_as_boolean",
|
|
279
|
-
"header_text",
|
|
280
|
-
"keep_version_file",
|
|
281
|
-
"no_async",
|
|
282
|
-
"no_namespace_folders",
|
|
283
|
-
"basic_setup_py",
|
|
284
|
-
"package_name",
|
|
285
|
-
"package_version",
|
|
286
|
-
"client_side_validation",
|
|
287
|
-
"tracing",
|
|
288
|
-
"multiapi",
|
|
289
|
-
"polymorphic_examples",
|
|
290
|
-
"models_mode",
|
|
291
|
-
"builders_visibility",
|
|
292
|
-
"show_operations",
|
|
293
|
-
"show_send_request",
|
|
294
|
-
"only_path_and_body_params_positional",
|
|
295
|
-
"version_tolerant",
|
|
296
|
-
"low_level_client",
|
|
297
|
-
"combine_operation_files",
|
|
298
|
-
"package_mode",
|
|
299
|
-
"package_pprint_name",
|
|
300
|
-
"packaging_files_config",
|
|
301
|
-
"default_optional_constants_to_none",
|
|
302
|
-
"generate_sample",
|
|
303
|
-
"generate_test",
|
|
304
|
-
"default_api_version",
|
|
305
|
-
"from_typespec",
|
|
306
|
-
"flavor",
|
|
307
|
-
"emit_cross_language_definition_file",
|
|
308
|
-
"validate_versioning",
|
|
309
|
-
]
|
|
310
|
-
return {f: getattr(self.options_retriever, f) for f in flags}
|
|
311
|
-
|
|
312
63
|
def get_yaml(self) -> Dict[str, Any]:
|
|
313
64
|
# tsp file doesn't have to be relative to output folder
|
|
314
65
|
with open(self.options["tsp_file"], "r", encoding="utf-8-sig") as fd:
|
|
@@ -319,21 +70,18 @@ class CodeGenerator(Plugin):
|
|
|
319
70
|
|
|
320
71
|
def process(self) -> bool:
|
|
321
72
|
# List the input file, should be only one
|
|
322
|
-
self._validate_code_model_options()
|
|
323
|
-
options = self._build_code_model_options()
|
|
324
73
|
yaml_data = self.get_yaml()
|
|
325
74
|
|
|
326
75
|
self.sort_exceptions(yaml_data)
|
|
327
76
|
|
|
328
|
-
if self.
|
|
77
|
+
if self.options["azure-arm"]:
|
|
329
78
|
self.remove_cloud_errors(yaml_data)
|
|
330
79
|
|
|
331
|
-
code_model = CodeModel(yaml_data=yaml_data, options=options)
|
|
332
|
-
if
|
|
80
|
+
code_model = CodeModel(yaml_data=yaml_data, options=self.options)
|
|
81
|
+
if self.options["flavor"] != "azure" and any(client.lro_operations for client in code_model.clients):
|
|
333
82
|
raise ValueError("Only support LROs for Azure SDKs")
|
|
334
83
|
serializer = self.get_serializer(code_model)
|
|
335
84
|
serializer.serialize()
|
|
336
|
-
|
|
337
85
|
return True
|
|
338
86
|
|
|
339
87
|
|
|
@@ -35,9 +35,6 @@ DEFAULT_LICENSE_DESCRIPTION = (
|
|
|
35
35
|
"SOFTWARE."
|
|
36
36
|
)
|
|
37
37
|
|
|
38
|
-
SWAGGER_PACKAGE_MODE = ["mgmtplane", "dataplane"] # for backward compatibility
|
|
39
|
-
TYPESPEC_PACKAGE_MODE = ["azure-mgmt", "azure-dataplane", "generic"]
|
|
40
|
-
VALID_PACKAGE_MODE = SWAGGER_PACKAGE_MODE + TYPESPEC_PACKAGE_MODE
|
|
41
38
|
NAME_LENGTH_LIMIT = 40
|
|
42
39
|
|
|
43
40
|
|
|
@@ -165,7 +165,7 @@ def build_type(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseType:
|
|
|
165
165
|
response: Optional[BaseType] = None
|
|
166
166
|
if yaml_data["type"] == "model":
|
|
167
167
|
# need to special case model to avoid recursion
|
|
168
|
-
if yaml_data["base"] == "json" or not code_model.options["
|
|
168
|
+
if yaml_data["base"] == "json" or not code_model.options["models-mode"]:
|
|
169
169
|
model_type = JSONModelType
|
|
170
170
|
elif yaml_data["base"] == "dpg":
|
|
171
171
|
model_type = DPGModelType # type: ignore
|
|
@@ -75,7 +75,7 @@ class BaseBuilder(
|
|
|
75
75
|
self.external_docs: Optional[Dict[str, Any]] = yaml_data.get("externalDocs")
|
|
76
76
|
self.client_namespace: str = yaml_data.get("clientNamespace", code_model.namespace)
|
|
77
77
|
|
|
78
|
-
if code_model.options["
|
|
78
|
+
if code_model.options["version-tolerant"] and yaml_data.get("abstract"):
|
|
79
79
|
_LOGGER.warning(
|
|
80
80
|
'Not going to generate operation "%s" because we are unable to generate this '
|
|
81
81
|
"type of operation right now. "
|
|
@@ -70,7 +70,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
70
70
|
self.config = Config.from_yaml(yaml_data, self.code_model)
|
|
71
71
|
self.is_subclient = is_subclient
|
|
72
72
|
self.request_builders = self._build_request_builders()
|
|
73
|
-
if self.code_model.options["
|
|
73
|
+
if self.code_model.options["show-operations"]:
|
|
74
74
|
self.operation_groups = [
|
|
75
75
|
OperationGroup.from_yaml(op_group, code_model, self)
|
|
76
76
|
for op_group in self.yaml_data.get("operationGroups", [])
|
|
@@ -91,7 +91,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
91
91
|
@property
|
|
92
92
|
def need_cloud_setting(self) -> bool:
|
|
93
93
|
return bool(
|
|
94
|
-
self.code_model.options.get("
|
|
94
|
+
self.code_model.options.get("azure-arm", False)
|
|
95
95
|
and self.credential_scopes is not None
|
|
96
96
|
and self.endpoint_parameter is not None
|
|
97
97
|
)
|
|
@@ -144,7 +144,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
144
144
|
return request_builders
|
|
145
145
|
|
|
146
146
|
def pipeline_class(self, async_mode: bool) -> str:
|
|
147
|
-
if self.code_model.options["
|
|
147
|
+
if self.code_model.options["azure-arm"]:
|
|
148
148
|
if async_mode:
|
|
149
149
|
return "AsyncARMPipelineClient"
|
|
150
150
|
return "ARMPipelineClient"
|
|
@@ -160,7 +160,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
160
160
|
@property
|
|
161
161
|
def send_request_name(self) -> str:
|
|
162
162
|
"""Name of the send request function"""
|
|
163
|
-
return "send_request" if self.code_model.options["
|
|
163
|
+
return "send_request" if self.code_model.options["show-send-request"] else "_send_request"
|
|
164
164
|
|
|
165
165
|
@property
|
|
166
166
|
def has_parameterized_host(self) -> bool:
|
|
@@ -186,7 +186,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
186
186
|
@property
|
|
187
187
|
def filename(self) -> str:
|
|
188
188
|
"""Name of the file for the client"""
|
|
189
|
-
if self.code_model.options["
|
|
189
|
+
if self.code_model.options["version-tolerant"] or self.code_model.options["low-level-client"]:
|
|
190
190
|
return "_client"
|
|
191
191
|
return f"_{self.legacy_filename}"
|
|
192
192
|
|
|
@@ -206,7 +206,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
206
206
|
def _imports_shared(self, async_mode: bool, **kwargs) -> FileImport:
|
|
207
207
|
file_import = FileImport(self.code_model)
|
|
208
208
|
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
209
|
-
if self.code_model.options["
|
|
209
|
+
if self.code_model.options["azure-arm"]:
|
|
210
210
|
file_import.add_submodule_import("azure.mgmt.core", self.pipeline_class(async_mode), ImportType.SDKCORE)
|
|
211
211
|
else:
|
|
212
212
|
file_import.add_submodule_import(
|
|
@@ -241,7 +241,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
241
241
|
"policies",
|
|
242
242
|
ImportType.SDKCORE,
|
|
243
243
|
)
|
|
244
|
-
if self.code_model.options["
|
|
244
|
+
if self.code_model.options["azure-arm"]:
|
|
245
245
|
async_prefix = "Async" if async_mode else ""
|
|
246
246
|
file_import.add_submodule_import(
|
|
247
247
|
"azure.mgmt.core.policies",
|
|
@@ -322,19 +322,21 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
322
322
|
)
|
|
323
323
|
serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
|
|
324
324
|
for og in self.operation_groups:
|
|
325
|
+
suffix = f".{og.filename}" if (not self.code_model.options["multiapi"]) and og.is_mixin else ""
|
|
325
326
|
file_import.add_submodule_import(
|
|
326
327
|
self.code_model.get_relative_import_path(
|
|
327
328
|
serialize_namespace,
|
|
328
329
|
self.code_model.get_imported_namespace_for_operation(og.client_namespace, async_mode),
|
|
329
|
-
)
|
|
330
|
+
)
|
|
331
|
+
+ suffix,
|
|
330
332
|
og.class_name,
|
|
331
333
|
ImportType.LOCAL,
|
|
332
334
|
)
|
|
333
335
|
|
|
334
|
-
if self.code_model.model_types and self.code_model.options["
|
|
336
|
+
if self.code_model.model_types and self.code_model.options["models-mode"] == "msrest":
|
|
335
337
|
path_to_models = ".." if async_mode else "."
|
|
336
338
|
file_import.add_submodule_import(path_to_models, "models", ImportType.LOCAL, alias="_models")
|
|
337
|
-
elif self.code_model.options["
|
|
339
|
+
elif self.code_model.options["models-mode"] == "msrest":
|
|
338
340
|
# in this case, we have client_models = {} in the service client, which needs a type annotation
|
|
339
341
|
# this import will always be commented, so will always add it to the typing section
|
|
340
342
|
file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB)
|
|
@@ -404,7 +406,7 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
404
406
|
|
|
405
407
|
@property
|
|
406
408
|
def sdk_moniker(self) -> str:
|
|
407
|
-
package_name = self.code_model.options
|
|
409
|
+
package_name = self.code_model.options.get("package-name")
|
|
408
410
|
if package_name and package_name.startswith("azure-"):
|
|
409
411
|
package_name = package_name[len("azure-") :]
|
|
410
412
|
return package_name if package_name else self.yaml_data["name"].lower()
|
|
@@ -421,14 +423,14 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
421
423
|
ImportType.SDKCORE,
|
|
422
424
|
)
|
|
423
425
|
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
424
|
-
if self.code_model.options
|
|
426
|
+
if self.code_model.options.get("package-version"):
|
|
425
427
|
serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
|
|
426
428
|
file_import.add_submodule_import(
|
|
427
429
|
self.code_model.get_relative_import_path(serialize_namespace, module_name="_version"),
|
|
428
430
|
"VERSION",
|
|
429
431
|
ImportType.LOCAL,
|
|
430
432
|
)
|
|
431
|
-
if self.code_model.options["
|
|
433
|
+
if self.code_model.options["azure-arm"]:
|
|
432
434
|
policy = "AsyncARMChallengeAuthenticationPolicy" if async_mode else "ARMChallengeAuthenticationPolicy"
|
|
433
435
|
file_import.add_submodule_import("azure.mgmt.core.policies", "ARMHttpLoggingPolicy", ImportType.SDKCORE)
|
|
434
436
|
file_import.add_submodule_import("azure.mgmt.core.policies", policy, ImportType.SDKCORE)
|
|
@@ -14,10 +14,11 @@ from .request_builder import RequestBuilder, OverloadedRequestBuilder
|
|
|
14
14
|
from .operation_group import OperationGroup
|
|
15
15
|
from .utils import NamespaceType
|
|
16
16
|
from .._utils import DEFAULT_HEADER_TEXT, DEFAULT_LICENSE_DESCRIPTION
|
|
17
|
+
from ... import OptionsDict
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
def _is_legacy(options) -> bool:
|
|
20
|
-
return not (options.get("
|
|
21
|
+
return not (options.get("version-tolerant") or options.get("low-level-client"))
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
def get_all_operation_groups_recursively(clients: List[Client]) -> List[OperationGroup]:
|
|
@@ -72,7 +73,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
72
73
|
def __init__(
|
|
73
74
|
self,
|
|
74
75
|
yaml_data: Dict[str, Any],
|
|
75
|
-
options:
|
|
76
|
+
options: OptionsDict,
|
|
76
77
|
) -> None:
|
|
77
78
|
self.yaml_data = yaml_data
|
|
78
79
|
self.options = options
|
|
@@ -86,7 +87,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
86
87
|
self.clients: List[Client] = [
|
|
87
88
|
Client.from_yaml(client_yaml_data, self) for client_yaml_data in yaml_data["clients"]
|
|
88
89
|
]
|
|
89
|
-
if self.options["
|
|
90
|
+
if self.options["models-mode"] and self.model_types:
|
|
90
91
|
self.sort_model_types()
|
|
91
92
|
self.named_unions: List[CombinedType] = [
|
|
92
93
|
t for t in self.types_map.values() if isinstance(t, CombinedType) and t.name
|
|
@@ -227,7 +228,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
227
228
|
@property
|
|
228
229
|
def rest_layer_name(self) -> str:
|
|
229
230
|
"""If we have a separate rest layer, what is its name?"""
|
|
230
|
-
return "rest" if self.options["
|
|
231
|
+
return "rest" if self.options["builders-visibility"] == "public" else "_rest"
|
|
231
232
|
|
|
232
233
|
@property
|
|
233
234
|
def client_filename(self) -> str:
|
|
@@ -247,12 +248,12 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
247
248
|
return (
|
|
248
249
|
self.need_utils_utils(async_mode, client_namespace)
|
|
249
250
|
or self.need_utils_serialization
|
|
250
|
-
or self.options["
|
|
251
|
+
or self.options["models-mode"] == "dpg"
|
|
251
252
|
)
|
|
252
253
|
|
|
253
254
|
@property
|
|
254
255
|
def need_utils_serialization(self) -> bool:
|
|
255
|
-
return not self.options["
|
|
256
|
+
return not self.options["client-side-validation"]
|
|
256
257
|
|
|
257
258
|
def need_utils_utils(self, async_mode: bool, client_namespace: str) -> bool:
|
|
258
259
|
return (
|
|
@@ -267,7 +268,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
267
268
|
(not async_mode)
|
|
268
269
|
and self.is_top_namespace(client_namespace)
|
|
269
270
|
and self.has_form_data
|
|
270
|
-
and self.options["
|
|
271
|
+
and self.options["models-mode"] == "dpg"
|
|
271
272
|
)
|
|
272
273
|
|
|
273
274
|
def need_utils_etag(self, client_namespace: str) -> bool:
|
|
@@ -292,7 +293,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
292
293
|
if client_namespace not in self._operations_folder_name:
|
|
293
294
|
name = "operations"
|
|
294
295
|
operation_groups = self.client_namespace_types.get(client_namespace, ClientNamespaceType()).operation_groups
|
|
295
|
-
if self.options["
|
|
296
|
+
if self.options["version-tolerant"] and all(og.is_mixin for og in operation_groups):
|
|
296
297
|
name = f"_{name}"
|
|
297
298
|
self._operations_folder_name[client_namespace] = name
|
|
298
299
|
return self._operations_folder_name[client_namespace]
|
|
@@ -427,7 +428,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
427
428
|
license_header = self.yaml_data.get("licenseInfo", {}).get("header", "")
|
|
428
429
|
else:
|
|
429
430
|
# typespec azure case without custom license and swagger case
|
|
430
|
-
license_header = self.options.get("
|
|
431
|
+
license_header = self.options.get("header-text") or DEFAULT_HEADER_TEXT
|
|
431
432
|
if license_header:
|
|
432
433
|
license_header = license_header.replace("\n", "\n# ")
|
|
433
434
|
license_header = (
|
|
@@ -170,7 +170,7 @@ class EnumType(BaseType):
|
|
|
170
170
|
:return: The type annotation for this schema
|
|
171
171
|
:rtype: str
|
|
172
172
|
"""
|
|
173
|
-
if self.code_model.options["
|
|
173
|
+
if self.code_model.options["models-mode"]:
|
|
174
174
|
|
|
175
175
|
module_name = ""
|
|
176
176
|
if kwargs.get("need_model_alias", True):
|
|
@@ -190,13 +190,13 @@ class EnumType(BaseType):
|
|
|
190
190
|
return self.value_type.get_declaration(value)
|
|
191
191
|
|
|
192
192
|
def docstring_text(self, **kwargs: Any) -> str:
|
|
193
|
-
if self.code_model.options["
|
|
193
|
+
if self.code_model.options["models-mode"]:
|
|
194
194
|
return self.name
|
|
195
195
|
return self.value_type.type_annotation(**kwargs)
|
|
196
196
|
|
|
197
197
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
198
198
|
"""The python type used for RST syntax input and type annotation."""
|
|
199
|
-
if self.code_model.options["
|
|
199
|
+
if self.code_model.options["models-mode"]:
|
|
200
200
|
type_annotation = self.value_type.type_annotation(**kwargs)
|
|
201
201
|
enum_type_annotation = f"{self.client_namespace}.models.{self.name}"
|
|
202
202
|
return f"{type_annotation} or ~{enum_type_annotation}"
|
|
@@ -230,7 +230,7 @@ class EnumType(BaseType):
|
|
|
230
230
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
231
231
|
file_import = FileImport(self.code_model)
|
|
232
232
|
file_import.merge(self.value_type.imports(**kwargs))
|
|
233
|
-
if self.code_model.options["
|
|
233
|
+
if self.code_model.options["models-mode"]:
|
|
234
234
|
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
235
235
|
|
|
236
236
|
serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
|
|
@@ -255,7 +255,7 @@ class FileImport:
|
|
|
255
255
|
msrest_import_type: MsrestImportType,
|
|
256
256
|
typing_section: TypingSection,
|
|
257
257
|
):
|
|
258
|
-
if self.code_model.options["
|
|
258
|
+
if self.code_model.options["client-side-validation"]:
|
|
259
259
|
if msrest_import_type == MsrestImportType.Module:
|
|
260
260
|
self.add_import("msrest.serialization", ImportType.SDKCORE, typing_section)
|
|
261
261
|
else:
|
|
@@ -34,9 +34,9 @@ class ListType(BaseType):
|
|
|
34
34
|
|
|
35
35
|
def type_annotation(self, **kwargs: Any) -> str:
|
|
36
36
|
if (
|
|
37
|
-
self.code_model.options["
|
|
37
|
+
self.code_model.options["version-tolerant"]
|
|
38
38
|
and self.element_type.is_xml
|
|
39
|
-
and not self.code_model.options["
|
|
39
|
+
and not self.code_model.options["models-mode"]
|
|
40
40
|
):
|
|
41
41
|
# this means we're version tolerant XML, we just return the XML element
|
|
42
42
|
return self.element_type.type_annotation(**kwargs)
|
|
@@ -68,13 +68,13 @@ class ListType(BaseType):
|
|
|
68
68
|
return ", ".join(attrs_list)
|
|
69
69
|
|
|
70
70
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
71
|
-
if self.code_model.options["
|
|
71
|
+
if self.code_model.options["version-tolerant"] and self.element_type.xml_metadata:
|
|
72
72
|
# this means we're version tolerant XML, we just return the XML element
|
|
73
73
|
return self.element_type.docstring_type(**kwargs)
|
|
74
74
|
return f"list[{self.element_type.docstring_type(**kwargs)}]"
|
|
75
75
|
|
|
76
76
|
def docstring_text(self, **kwargs: Any) -> str:
|
|
77
|
-
if self.code_model.options["
|
|
77
|
+
if self.code_model.options["version-tolerant"] and self.element_type.xml_metadata:
|
|
78
78
|
# this means we're version tolerant XML, we just return the XML element
|
|
79
79
|
return self.element_type.docstring_text(**kwargs)
|
|
80
80
|
return f"list of {self.element_type.docstring_text(**kwargs)}"
|
|
@@ -129,9 +129,9 @@ class ListType(BaseType):
|
|
|
129
129
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
130
130
|
file_import = FileImport(self.code_model)
|
|
131
131
|
if not (
|
|
132
|
-
self.code_model.options["
|
|
132
|
+
self.code_model.options["version-tolerant"]
|
|
133
133
|
and self.element_type.is_xml
|
|
134
|
-
and not self.code_model.options["
|
|
134
|
+
and not self.code_model.options["models-mode"]
|
|
135
135
|
):
|
|
136
136
|
file_import.add_submodule_import("typing", "List", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
137
137
|
file_import.merge(self.element_type.imports(**kwargs))
|
|
@@ -125,7 +125,7 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
125
125
|
ImportType.SDKCORE,
|
|
126
126
|
)
|
|
127
127
|
if (
|
|
128
|
-
self.code_model.options["
|
|
128
|
+
self.code_model.options["models-mode"] == "dpg"
|
|
129
129
|
and self.lro_response
|
|
130
130
|
and self.lro_response.type
|
|
131
131
|
and self.lro_response.type.type == "model"
|