@autorest/python 5.13.0 → 5.16.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/ChangeLog.md +67 -0
- package/autorest/__init__.py +1 -2
- package/autorest/black/__init__.py +12 -5
- package/autorest/codegen/__init__.py +239 -105
- package/autorest/codegen/models/__init__.py +29 -18
- package/autorest/codegen/models/base_builder.py +48 -11
- package/autorest/codegen/models/base_model.py +6 -4
- package/autorest/codegen/models/base_schema.py +21 -24
- package/autorest/codegen/models/client.py +70 -20
- package/autorest/codegen/models/code_model.py +144 -129
- package/autorest/codegen/models/constant_schema.py +32 -16
- package/autorest/codegen/models/credential_model.py +55 -0
- package/autorest/codegen/models/credential_schema.py +21 -16
- package/autorest/codegen/models/credential_schema_policy.py +11 -15
- package/autorest/codegen/models/dictionary_schema.py +27 -24
- package/autorest/codegen/models/enum_schema.py +41 -62
- package/autorest/codegen/models/imports.py +72 -41
- package/autorest/codegen/models/list_schema.py +40 -18
- package/autorest/codegen/models/lro_operation.py +61 -25
- package/autorest/codegen/models/lro_paging_operation.py +5 -6
- package/autorest/codegen/models/object_schema.py +113 -59
- package/autorest/codegen/models/operation.py +251 -111
- package/autorest/codegen/models/operation_group.py +67 -32
- package/autorest/codegen/models/paging_operation.py +48 -21
- package/autorest/codegen/models/parameter.py +182 -90
- package/autorest/codegen/models/parameter_list.py +184 -163
- package/autorest/codegen/models/primitive_schemas.py +89 -70
- package/autorest/codegen/models/property.py +49 -31
- package/autorest/codegen/models/request_builder.py +67 -32
- package/autorest/codegen/models/request_builder_parameter.py +54 -23
- package/autorest/codegen/models/request_builder_parameter_list.py +77 -108
- package/autorest/codegen/models/schema_request.py +16 -6
- package/autorest/codegen/models/schema_response.py +35 -17
- package/autorest/codegen/models/utils.py +24 -1
- package/autorest/codegen/serializers/__init__.py +273 -89
- package/autorest/codegen/serializers/builder_serializer.py +711 -333
- package/autorest/codegen/serializers/client_serializer.py +114 -43
- package/autorest/codegen/serializers/general_serializer.py +84 -25
- package/autorest/codegen/serializers/import_serializer.py +93 -31
- package/autorest/codegen/serializers/metadata_serializer.py +73 -24
- package/autorest/codegen/serializers/model_base_serializer.py +42 -14
- package/autorest/codegen/serializers/model_generic_serializer.py +1 -4
- package/autorest/codegen/serializers/model_init_serializer.py +5 -1
- package/autorest/codegen/serializers/model_python3_serializer.py +9 -8
- package/autorest/codegen/serializers/operation_groups_serializer.py +20 -8
- package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
- package/autorest/codegen/serializers/patch_serializer.py +14 -2
- package/autorest/codegen/serializers/{rest_serializer.py → request_builders_serializer.py} +29 -12
- package/autorest/codegen/serializers/utils.py +60 -21
- package/autorest/codegen/templates/CHANGELOG.md.jinja2 +6 -0
- package/autorest/codegen/templates/LICENSE.jinja2 +21 -0
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +7 -0
- package/autorest/codegen/templates/README.md.jinja2 +105 -0
- package/autorest/codegen/templates/config.py.jinja2 +4 -4
- package/autorest/codegen/templates/dev_requirements.txt.jinja2 +10 -0
- package/autorest/codegen/templates/enum.py.jinja2 +1 -1
- package/autorest/codegen/templates/enum_container.py.jinja2 +0 -1
- package/autorest/codegen/templates/init.py.jinja2 +9 -6
- package/autorest/codegen/templates/keywords.jinja2 +14 -1
- package/autorest/codegen/templates/lro_operation.py.jinja2 +5 -7
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +5 -7
- package/autorest/codegen/templates/metadata.json.jinja2 +10 -9
- package/autorest/codegen/templates/model.py.jinja2 +1 -6
- package/autorest/codegen/templates/model_init.py.jinja2 +7 -4
- package/autorest/codegen/templates/operation.py.jinja2 +8 -11
- package/autorest/codegen/templates/operation_group.py.jinja2 +15 -18
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -2
- package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
- package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
- package/autorest/codegen/templates/patch.py.jinja2 +18 -29
- package/autorest/codegen/templates/request_builder.py.jinja2 +19 -14
- package/autorest/codegen/templates/setup.py.jinja2 +79 -20
- package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
- package/autorest/jsonrpc/__init__.py +7 -12
- package/autorest/jsonrpc/localapi.py +4 -3
- package/autorest/jsonrpc/server.py +13 -6
- package/autorest/jsonrpc/stdstream.py +13 -6
- package/autorest/m2r/__init__.py +5 -8
- package/autorest/multiapi/__init__.py +24 -14
- package/autorest/multiapi/models/client.py +21 -11
- package/autorest/multiapi/models/code_model.py +23 -10
- package/autorest/multiapi/models/config.py +4 -1
- package/autorest/multiapi/models/constant_global_parameter.py +1 -0
- package/autorest/multiapi/models/global_parameter.py +2 -1
- package/autorest/multiapi/models/global_parameters.py +14 -8
- package/autorest/multiapi/models/imports.py +35 -18
- package/autorest/multiapi/models/mixin_operation.py +5 -5
- package/autorest/multiapi/models/operation_group.py +2 -1
- package/autorest/multiapi/models/operation_mixin_group.py +21 -10
- package/autorest/multiapi/serializers/__init__.py +18 -23
- package/autorest/multiapi/serializers/import_serializer.py +47 -15
- package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
- package/autorest/multiapi/utils.py +3 -3
- package/autorest/namer/__init__.py +2 -4
- package/autorest/namer/name_converter.py +200 -103
- package/autorest/namer/python_mappings.py +10 -22
- package/package.json +3 -3
- package/run-python3.js +2 -3
- package/venvtools.py +1 -1
- package/autorest/codegen/models/rest.py +0 -42
|
@@ -3,32 +3,41 @@
|
|
|
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 Dict, List, Any, Optional
|
|
6
|
+
from typing import Dict, List, Any, Optional, TYPE_CHECKING
|
|
7
7
|
|
|
8
8
|
from .base_model import BaseModel
|
|
9
9
|
from .parameter import Parameter
|
|
10
10
|
from .parameter_list import ParameterList
|
|
11
11
|
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from .code_model import CodeModel
|
|
14
|
+
|
|
15
|
+
|
|
12
16
|
class SchemaRequest(BaseModel):
|
|
13
17
|
def __init__(
|
|
14
18
|
self,
|
|
15
19
|
yaml_data: Dict[str, Any],
|
|
20
|
+
code_model: "CodeModel",
|
|
16
21
|
content_types: List[str],
|
|
17
22
|
parameters: ParameterList,
|
|
18
23
|
) -> None:
|
|
19
|
-
super().__init__(yaml_data)
|
|
24
|
+
super().__init__(yaml_data, code_model)
|
|
20
25
|
self.content_types = content_types
|
|
21
26
|
self.parameters = parameters
|
|
22
27
|
|
|
23
28
|
@property
|
|
24
29
|
def is_stream_request(self) -> bool:
|
|
25
30
|
"""Is the request expected to be streamable, like a download."""
|
|
26
|
-
if self.yaml_data[
|
|
27
|
-
return
|
|
31
|
+
if self.yaml_data["protocol"]["http"].get("knownMediaType"):
|
|
32
|
+
return (
|
|
33
|
+
self.yaml_data["protocol"]["http"]["knownMediaType"] == "binary"
|
|
34
|
+
) # FIXME: this might be an m4 issue
|
|
28
35
|
return self.yaml_data["protocol"]["http"].get("binary", False)
|
|
29
36
|
|
|
30
37
|
@classmethod
|
|
31
|
-
def from_yaml(
|
|
38
|
+
def from_yaml(
|
|
39
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
40
|
+
) -> "SchemaRequest":
|
|
32
41
|
|
|
33
42
|
parameters: Optional[List[Parameter]] = [
|
|
34
43
|
Parameter.from_yaml(yaml, code_model=code_model)
|
|
@@ -37,8 +46,9 @@ class SchemaRequest(BaseModel):
|
|
|
37
46
|
|
|
38
47
|
return cls(
|
|
39
48
|
yaml_data=yaml_data,
|
|
49
|
+
code_model=code_model,
|
|
40
50
|
content_types=yaml_data["protocol"]["http"].get("mediaTypes", []),
|
|
41
|
-
parameters=ParameterList(code_model, parameters)
|
|
51
|
+
parameters=ParameterList(code_model, parameters),
|
|
42
52
|
)
|
|
43
53
|
|
|
44
54
|
def __repr__(self) -> str:
|
|
@@ -3,12 +3,17 @@
|
|
|
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 Dict, Optional, List, Union, Any, cast
|
|
6
|
+
from typing import Dict, Optional, List, Union, Any, cast, TYPE_CHECKING
|
|
7
7
|
|
|
8
8
|
from .base_model import BaseModel
|
|
9
9
|
from .base_schema import BaseSchema
|
|
10
10
|
from .object_schema import ObjectSchema
|
|
11
11
|
from .imports import FileImport, ImportType
|
|
12
|
+
from .utils import get_schema
|
|
13
|
+
from .primitive_schemas import IOSchema
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from .code_model import CodeModel
|
|
12
17
|
|
|
13
18
|
|
|
14
19
|
class HeaderResponse:
|
|
@@ -25,13 +30,14 @@ class SchemaResponse(BaseModel):
|
|
|
25
30
|
def __init__(
|
|
26
31
|
self,
|
|
27
32
|
yaml_data: Dict[str, Any],
|
|
33
|
+
code_model: "CodeModel",
|
|
28
34
|
schema: Optional[BaseSchema],
|
|
29
35
|
content_types: List[str],
|
|
30
36
|
status_codes: List[Union[str, int]],
|
|
31
37
|
headers: List[HeaderResponse],
|
|
32
38
|
binary: bool,
|
|
33
39
|
) -> None:
|
|
34
|
-
super().__init__(yaml_data)
|
|
40
|
+
super().__init__(yaml_data, code_model)
|
|
35
41
|
self.schema = schema
|
|
36
42
|
self.content_types = content_types
|
|
37
43
|
self.status_codes = status_codes
|
|
@@ -41,14 +47,12 @@ class SchemaResponse(BaseModel):
|
|
|
41
47
|
|
|
42
48
|
@property
|
|
43
49
|
def has_body(self) -> bool:
|
|
44
|
-
"""Tell if that response defines a body.
|
|
45
|
-
"""
|
|
50
|
+
"""Tell if that response defines a body."""
|
|
46
51
|
return bool(self.schema)
|
|
47
52
|
|
|
48
53
|
@property
|
|
49
54
|
def has_headers(self) -> bool:
|
|
50
|
-
"""Tell if that response defines headers.
|
|
51
|
-
"""
|
|
55
|
+
"""Tell if that response defines headers."""
|
|
52
56
|
return bool(self.headers)
|
|
53
57
|
|
|
54
58
|
@property
|
|
@@ -57,13 +61,12 @@ class SchemaResponse(BaseModel):
|
|
|
57
61
|
return self.schema.serialization_type
|
|
58
62
|
return "None"
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
def operation_type_annotation(self) -> str:
|
|
64
|
+
def type_annotation(self, *, is_operation_file: bool = False) -> str:
|
|
62
65
|
if not self.schema:
|
|
63
66
|
return "None"
|
|
64
67
|
if self.nullable:
|
|
65
|
-
return f"Optional[{self.schema.
|
|
66
|
-
return self.schema.
|
|
68
|
+
return f"Optional[{self.schema.type_annotation(is_operation_file=is_operation_file)}]"
|
|
69
|
+
return self.schema.type_annotation(is_operation_file=is_operation_file)
|
|
67
70
|
|
|
68
71
|
@property
|
|
69
72
|
def docstring_text(self) -> str:
|
|
@@ -99,24 +102,39 @@ class SchemaResponse(BaseModel):
|
|
|
99
102
|
def imports(self, code_model) -> FileImport:
|
|
100
103
|
file_import = FileImport()
|
|
101
104
|
if not code_model.options["models_mode"] and self.is_xml:
|
|
102
|
-
file_import.add_submodule_import(
|
|
105
|
+
file_import.add_submodule_import(
|
|
106
|
+
"xml.etree", "ElementTree", ImportType.STDLIB, alias="ET"
|
|
107
|
+
)
|
|
103
108
|
return file_import
|
|
104
109
|
|
|
105
110
|
@classmethod
|
|
106
|
-
def from_yaml(
|
|
107
|
-
|
|
111
|
+
def from_yaml(
|
|
112
|
+
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
113
|
+
) -> "SchemaResponse":
|
|
114
|
+
binary = yaml_data.get("binary", False)
|
|
115
|
+
if binary:
|
|
116
|
+
schema: BaseSchema = IOSchema(yaml_data={}, code_model=code_model)
|
|
117
|
+
else:
|
|
118
|
+
schema = get_schema(code_model, yaml_data.get("schema"))
|
|
108
119
|
return cls(
|
|
109
120
|
yaml_data=yaml_data,
|
|
110
|
-
|
|
121
|
+
code_model=code_model,
|
|
122
|
+
schema=schema,
|
|
111
123
|
content_types=yaml_data["protocol"]["http"].get("mediaTypes", []),
|
|
112
124
|
status_codes=[
|
|
113
|
-
int(code) if code != "default" else "default"
|
|
125
|
+
int(code) if code != "default" else "default"
|
|
126
|
+
for code in yaml_data["protocol"]["http"]["statusCodes"]
|
|
114
127
|
],
|
|
115
128
|
headers=[
|
|
116
|
-
HeaderResponse(
|
|
129
|
+
HeaderResponse(
|
|
130
|
+
header_prop["header"],
|
|
131
|
+
get_schema(
|
|
132
|
+
code_model, header_prop["schema"], header_prop["header"]
|
|
133
|
+
),
|
|
134
|
+
)
|
|
117
135
|
for header_prop in yaml_data["protocol"]["http"].get("headers", [])
|
|
118
136
|
],
|
|
119
|
-
binary=
|
|
137
|
+
binary=binary,
|
|
120
138
|
)
|
|
121
139
|
|
|
122
140
|
def __repr__(self) -> str:
|
|
@@ -4,5 +4,28 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import re
|
|
7
|
+
from typing import Any, TYPE_CHECKING
|
|
8
|
+
import logging
|
|
9
|
+
from .base_schema import BaseSchema
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from .code_model import CodeModel
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
_LOGGER = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
JSON_REGEXP = re.compile(r"^(application|text)/(.+\+)?json$")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_schema(
|
|
21
|
+
code_model: "CodeModel", schema: Any, serialized_name: str = "unknown"
|
|
22
|
+
) -> BaseSchema:
|
|
23
|
+
if not isinstance(schema, dict):
|
|
24
|
+
return schema
|
|
25
|
+
schema_id = id(schema)
|
|
26
|
+
_LOGGER.debug("Looking for id %s for member %s", schema_id, serialized_name)
|
|
27
|
+
try:
|
|
28
|
+
return code_model.lookup_schema(schema_id)
|
|
29
|
+
except KeyError:
|
|
30
|
+
_LOGGER.critical("Unable to ref the object")
|
|
31
|
+
raise
|