@autorest/python 6.13.7 → 6.13.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autorest/codegen/__init__.py +2 -0
- package/autorest/codegen/models/code_model.py +1 -0
- package/autorest/codegen/models/enum_type.py +3 -0
- package/autorest/codegen/models/model_type.py +3 -0
- package/autorest/codegen/models/operation.py +4 -1
- package/autorest/codegen/serializers/__init__.py +5 -0
- package/autorest/codegen/serializers/general_serializer.py +37 -0
- package/autorest/codegen/templates/packaging_templates/README.md.jinja2 +1 -1
- package/package.json +1 -1
|
@@ -38,6 +38,7 @@ class OptionsRetriever:
|
|
|
38
38
|
"polymorphic-examples": 5,
|
|
39
39
|
"generate-sample": False,
|
|
40
40
|
"from-typespec": False,
|
|
41
|
+
"emit-cross-language-definition-file": False,
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
@property
|
|
@@ -333,6 +334,7 @@ class CodeGenerator(Plugin):
|
|
|
333
334
|
"from_typespec",
|
|
334
335
|
"flavor",
|
|
335
336
|
"company_name",
|
|
337
|
+
"emit_cross_language_definition_file",
|
|
336
338
|
]
|
|
337
339
|
return {f: getattr(self.options_retriever, f) for f in flags}
|
|
338
340
|
|
|
@@ -75,6 +75,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
75
75
|
self.named_unions: List[CombinedType] = [
|
|
76
76
|
t for t in self.types_map.values() if isinstance(t, CombinedType) and t.name
|
|
77
77
|
]
|
|
78
|
+
self.cross_language_package_id = self.yaml_data.get("crossLanguagePackageId")
|
|
78
79
|
|
|
79
80
|
@property
|
|
80
81
|
def has_form_data(self) -> bool:
|
|
@@ -134,6 +134,9 @@ class EnumType(BaseType):
|
|
|
134
134
|
self.values = values
|
|
135
135
|
self.value_type = value_type
|
|
136
136
|
self.internal: bool = self.yaml_data.get("internal", False)
|
|
137
|
+
self.cross_language_definition_id: Optional[str] = self.yaml_data.get(
|
|
138
|
+
"crossLanguageDefinitionId"
|
|
139
|
+
)
|
|
137
140
|
|
|
138
141
|
def __lt__(self, other):
|
|
139
142
|
return self.name.lower() < other.name.lower()
|
|
@@ -75,6 +75,9 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
75
75
|
self.internal: bool = self.yaml_data.get("internal", False)
|
|
76
76
|
self.snake_case_name: str = self.yaml_data["snakeCaseName"]
|
|
77
77
|
self.page_result_model: bool = self.yaml_data.get("pageResultModel", False)
|
|
78
|
+
self.cross_language_definition_id: Optional[str] = self.yaml_data.get(
|
|
79
|
+
"crossLanguageDefinitionId"
|
|
80
|
+
)
|
|
78
81
|
|
|
79
82
|
@property
|
|
80
83
|
def flattened_property(self) -> Optional[Property]:
|
|
@@ -54,7 +54,7 @@ def is_internal(target: Optional[BaseType]) -> bool:
|
|
|
54
54
|
return isinstance(target, ModelType) and target.base == "dpg" and target.internal
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
class OperationBase( # pylint: disable=too-many-public-methods
|
|
57
|
+
class OperationBase( # pylint: disable=too-many-public-methods,too-many-instance-attributes
|
|
58
58
|
Generic[ResponseType], BaseBuilder[ParameterList, List["Operation"]]
|
|
59
59
|
):
|
|
60
60
|
def __init__(
|
|
@@ -91,6 +91,9 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
91
91
|
if self.internal:
|
|
92
92
|
self.name = "_" + self.name
|
|
93
93
|
self.has_etag: bool = self.yaml_data.get("hasEtag", False)
|
|
94
|
+
self.cross_language_definition_id: Optional[str] = self.yaml_data.get(
|
|
95
|
+
"crossLanguageDefinitionId"
|
|
96
|
+
)
|
|
94
97
|
|
|
95
98
|
@property
|
|
96
99
|
def has_form_data_body(self):
|
|
@@ -522,6 +522,11 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
522
522
|
namespace_path / Path("_validation.py"),
|
|
523
523
|
general_serializer.serialize_validation_file(),
|
|
524
524
|
)
|
|
525
|
+
if self.code_model.options.get("emit_cross_language_definition_file"):
|
|
526
|
+
self.write_file(
|
|
527
|
+
namespace_path / Path("apiview_mapping_python.json"),
|
|
528
|
+
general_serializer.serialize_cross_language_definition_file(),
|
|
529
|
+
)
|
|
525
530
|
|
|
526
531
|
# Write the setup file
|
|
527
532
|
if self.code_model.options["basic_setup_py"]:
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
+
import json
|
|
6
7
|
from typing import Any, List
|
|
7
8
|
from jinja2 import Environment
|
|
8
9
|
from .import_serializer import FileImportSerializer, TypingSection
|
|
@@ -196,3 +197,39 @@ class GeneralSerializer(BaseSerializer):
|
|
|
196
197
|
def serialize_validation_file(self) -> str:
|
|
197
198
|
template = self.env.get_template("validation.py.jinja2")
|
|
198
199
|
return template.render(code_model=self.code_model)
|
|
200
|
+
|
|
201
|
+
def serialize_cross_language_definition_file(self) -> str:
|
|
202
|
+
cross_langauge_def_dict = {
|
|
203
|
+
f"{self.code_model.namespace}.models.{model.name}": model.cross_language_definition_id
|
|
204
|
+
for model in self.code_model.model_types
|
|
205
|
+
}
|
|
206
|
+
cross_langauge_def_dict.update(
|
|
207
|
+
{
|
|
208
|
+
f"{self.code_model.namespace}.models.{enum.name}": enum.cross_language_definition_id
|
|
209
|
+
for enum in self.code_model.enums
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
cross_langauge_def_dict.update(
|
|
213
|
+
{
|
|
214
|
+
(
|
|
215
|
+
f"{self.code_model.namespace}.{client.name}."
|
|
216
|
+
+ (
|
|
217
|
+
""
|
|
218
|
+
if operation_group.is_mixin
|
|
219
|
+
else f"{operation_group.property_name}."
|
|
220
|
+
)
|
|
221
|
+
+ f"{operation.name}"
|
|
222
|
+
): operation.cross_language_definition_id
|
|
223
|
+
for client in self.code_model.clients
|
|
224
|
+
for operation_group in client.operation_groups
|
|
225
|
+
for operation in operation_group.operations
|
|
226
|
+
if not operation.name.startswith("_")
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
return json.dumps(
|
|
230
|
+
{
|
|
231
|
+
"CrossLanguagePackageId": self.code_model.cross_language_package_id,
|
|
232
|
+
"CrossLanguageDefinitionId": cross_langauge_def_dict,
|
|
233
|
+
},
|
|
234
|
+
indent=4,
|
|
235
|
+
)
|