@autorest/python 6.10.1 → 6.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autorest/codegen/models/combined_type.py +12 -18
- package/autorest/codegen/models/parameter.py +1 -1
- package/autorest/codegen/serializers/builder_serializer.py +18 -7
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_tools.jinja2 +6 -2
- package/package.json +1 -1
- package/requirements.txt +1 -0
|
@@ -3,15 +3,14 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import Any, Dict, List, Optional, TYPE_CHECKING
|
|
6
|
+
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Type, Tuple, Union
|
|
7
7
|
import re
|
|
8
8
|
from autorest.codegen.models.imports import FileImport, ImportType, TypingSection
|
|
9
9
|
from .base import BaseType
|
|
10
|
-
from .model_type import
|
|
10
|
+
from .model_type import ModelType
|
|
11
11
|
|
|
12
12
|
if TYPE_CHECKING:
|
|
13
13
|
from .code_model import CodeModel
|
|
14
|
-
from .model_type import ModelType
|
|
15
14
|
|
|
16
15
|
|
|
17
16
|
class CombinedType(BaseType):
|
|
@@ -129,19 +128,14 @@ class CombinedType(BaseType):
|
|
|
129
128
|
[build_type(t, code_model) for t in yaml_data["types"]],
|
|
130
129
|
)
|
|
131
130
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
pass
|
|
131
|
+
def target_model_subtype(
|
|
132
|
+
self,
|
|
133
|
+
target_types: Union[
|
|
134
|
+
Tuple[Type[ModelType]],
|
|
135
|
+
Tuple[Type[ModelType], Type[ModelType]],
|
|
136
|
+
],
|
|
137
|
+
) -> Optional[ModelType]:
|
|
138
|
+
for sub_t in self.types:
|
|
139
|
+
if isinstance(sub_t, target_types):
|
|
140
|
+
return sub_t # type: ignore
|
|
143
141
|
return None
|
|
144
|
-
|
|
145
|
-
@property
|
|
146
|
-
def json_subtype(self) -> Optional[JSONModelType]:
|
|
147
|
-
return CombinedType._get_json_model_type(self)
|
|
@@ -271,7 +271,7 @@ class BodyParameter(_ParameterBase):
|
|
|
271
271
|
@property
|
|
272
272
|
def has_json_model_type(self) -> bool:
|
|
273
273
|
if isinstance(self.type, CombinedType):
|
|
274
|
-
return self.type.
|
|
274
|
+
return self.type.target_model_subtype((JSONModelType,)) is not None
|
|
275
275
|
return isinstance(self.type, JSONModelType)
|
|
276
276
|
|
|
277
277
|
@classmethod
|
|
@@ -30,6 +30,8 @@ from ..models import (
|
|
|
30
30
|
Property,
|
|
31
31
|
RequestBuilderType,
|
|
32
32
|
CombinedType,
|
|
33
|
+
JSONModelType,
|
|
34
|
+
DPGModelType,
|
|
33
35
|
ParameterListType,
|
|
34
36
|
ByteArraySchema,
|
|
35
37
|
)
|
|
@@ -181,8 +183,10 @@ def _serialize_json_model_body(
|
|
|
181
183
|
for property_name, parameter_name in body_parameter.property_to_parameter_name.items()
|
|
182
184
|
)
|
|
183
185
|
model_type = cast(ModelType, body_parameter.type)
|
|
184
|
-
if isinstance(model_type, CombinedType) and model_type.
|
|
185
|
-
|
|
186
|
+
if isinstance(model_type, CombinedType) and model_type.target_model_subtype(
|
|
187
|
+
(JSONModelType,)
|
|
188
|
+
):
|
|
189
|
+
model_type = model_type.target_model_subtype((JSONModelType,))
|
|
186
190
|
retval.append(f" {body_parameter.client_name} = {{{parameter_string}}}")
|
|
187
191
|
retval.append(f" {body_parameter.client_name} = {{")
|
|
188
192
|
retval.append(
|
|
@@ -320,6 +324,10 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
320
324
|
description_list.append("")
|
|
321
325
|
return description_list
|
|
322
326
|
|
|
327
|
+
@staticmethod
|
|
328
|
+
def line_too_long(docs: List[str]) -> bool:
|
|
329
|
+
return any(len(line) > 120 for line in docs)
|
|
330
|
+
|
|
323
331
|
def example_template(self, builder: BuilderType) -> List[str]:
|
|
324
332
|
template = []
|
|
325
333
|
if builder.abstract:
|
|
@@ -376,18 +384,21 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
376
384
|
|
|
377
385
|
if (
|
|
378
386
|
isinstance(body_param.type, (ListType, DictionaryType))
|
|
379
|
-
and self.code_model.options["models_mode"]
|
|
387
|
+
and self.code_model.options["models_mode"] == "msrest"
|
|
380
388
|
):
|
|
381
389
|
return template
|
|
382
390
|
|
|
383
|
-
if isinstance(body_param.type, ModelType) and body_param.type.base
|
|
391
|
+
if isinstance(body_param.type, ModelType) and body_param.type.base == "msrest":
|
|
384
392
|
return template
|
|
385
393
|
|
|
386
394
|
json_type = body_param.type
|
|
387
395
|
if isinstance(body_param.type, CombinedType):
|
|
388
|
-
|
|
396
|
+
target_model_type = body_param.type.target_model_subtype(
|
|
397
|
+
(JSONModelType, DPGModelType)
|
|
398
|
+
)
|
|
399
|
+
if target_model_type is None:
|
|
389
400
|
return template
|
|
390
|
-
json_type =
|
|
401
|
+
json_type = target_model_type
|
|
391
402
|
|
|
392
403
|
polymorphic_subtypes: List[ModelType] = []
|
|
393
404
|
json_type.get_polymorphic_subtypes(polymorphic_subtypes)
|
|
@@ -597,7 +608,7 @@ class _OperationSerializer(
|
|
|
597
608
|
|
|
598
609
|
def example_template(self, builder: OperationType) -> List[str]:
|
|
599
610
|
retval = super().example_template(builder)
|
|
600
|
-
if self.code_model.options["models_mode"]:
|
|
611
|
+
if self.code_model.options["models_mode"] == "msrest":
|
|
601
612
|
return retval
|
|
602
613
|
for response in builder.responses:
|
|
603
614
|
polymorphic_subtypes: List[ModelType] = []
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{% import 'operation_tools.jinja2' as op_tools %}
|
|
2
2
|
{% set operations_description = "async operations" if async_mode else "operations" %}
|
|
3
3
|
{% set return_none_type_annotation = " -> None" if async_mode else "" %}
|
|
4
|
-
# pylint: disable=too-many-lines
|
|
4
|
+
# pylint: disable=too-many-lines,too-many-statements
|
|
5
5
|
# coding=utf-8
|
|
6
6
|
{{ code_model.options['license_header'] }}
|
|
7
7
|
{{ imports }}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{% macro wrap_string(string, wrapstring, width=95) %}{{ string | wordwrap(width=width, break_long_words=False, break_on_hyphens=False, wrapstring=wrapstring)}}{% endmacro %}
|
|
2
2
|
|
|
3
3
|
{% macro description(builder, serializer) %}
|
|
4
|
+
{% set example_template = serializer.example_template(builder) %}
|
|
4
5
|
{% for description in serializer.description_and_summary(builder) %}
|
|
5
6
|
{% if description %}
|
|
6
7
|
{% set description = wrap_string(description, wrapstring='\n') %}
|
|
8
|
+
{% if serializer.line_too_long(example_template) and loop.first %}
|
|
9
|
+
# pylint: disable=line-too-long
|
|
10
|
+
{% endif %}
|
|
7
11
|
{{ '"""' + description if loop.first else description }}
|
|
8
12
|
{% else %}
|
|
9
13
|
|
|
@@ -16,11 +20,11 @@
|
|
|
16
20
|
|
|
17
21
|
{% endif %}
|
|
18
22
|
{% endfor %}
|
|
19
|
-
{% if
|
|
23
|
+
{% if example_template %}
|
|
20
24
|
|
|
21
25
|
Example:
|
|
22
26
|
.. code-block:: python
|
|
23
|
-
{% for template_line in
|
|
27
|
+
{% for template_line in example_template %}
|
|
24
28
|
{% if template_line %}
|
|
25
29
|
{% set wrap_amount = (template_line | length) - (template_line.lstrip() | length) + 10 %}
|
|
26
30
|
{{ wrap_string(template_line, wrapstring='\n' + " " * wrap_amount, width=(95 - wrap_amount)) }}
|
package/package.json
CHANGED
package/requirements.txt
CHANGED