Skip to content
Merged

LLC #875

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
6549ef5
temp
iscai-msft Jan 20, 2021
1b87d8e
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Jan 20, 2021
a78dc5d
split operation code into separate request object
iscai-msft Jan 21, 2021
647574d
generate request in separate method, passing vanilla
iscai-msft Jan 21, 2021
a790523
separate out response handling jinja code
iscai-msft Jan 22, 2021
50c486f
make work for lro
iscai-msft Jan 25, 2021
8a158f2
make work for paging
iscai-msft Jan 26, 2021
71e007f
fix response headers
iscai-msft Jan 27, 2021
0da9058
trying to find lro + paging differences
iscai-msft Jan 27, 2021
cecae05
fix lro + paging
iscai-msft Jan 27, 2021
0b6bb32
combine sync and async param method signatures
iscai-msft Jan 27, 2021
02921e4
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Jan 27, 2021
2005c06
duplicate parameters onto operation
iscai-msft Jan 27, 2021
a8a5089
make request parameters different
iscai-msft Jan 27, 2021
648b065
deal with flattening
iscai-msft Jan 27, 2021
b5e1b7a
fix multipart
iscai-msft Jan 28, 2021
be49a4d
fix multiple media types
iscai-msft Jan 28, 2021
5d14e43
grouping
iscai-msft Jan 28, 2021
982dd37
fix xml
iscai-msft Jan 28, 2021
7f5c2f2
fix multiapi
iscai-msft Jan 28, 2021
8f33e8e
make grouped params private in high level operation, public in request
iscai-msft Jan 28, 2021
879a8f3
pylint and mypy
iscai-msft Jan 28, 2021
1b97770
fix unittests
iscai-msft Jan 28, 2021
dfe3b73
fix operation spacing
iscai-msft Jan 28, 2021
0036595
allow users to pass in request url through template_url kwarg
iscai-msft Feb 2, 2021
d2dd25c
remove _body = _body
iscai-msft Feb 2, 2021
553c19f
add back lro initial operation
iscai-msft Feb 9, 2021
02fd740
merge autorestv3
iscai-msft Feb 9, 2021
4035381
fix type annotations for multiple media types
iscai-msft Feb 9, 2021
7d1d75b
remove added typing for kwargs in async
iscai-msft Feb 9, 2021
5f5c57c
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Feb 9, 2021
9c515f8
fix pylint
iscai-msft Feb 9, 2021
93b1104
fix mypy
iscai-msft Feb 9, 2021
b5d606e
fix unittests
iscai-msft Feb 10, 2021
a90b361
fix media types
iscai-msft Feb 10, 2021
40c324e
fix multiple media types serialization
iscai-msft Feb 10, 2021
c4cbfe5
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Feb 10, 2021
04caf48
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Feb 10, 2021
ca14ed4
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Feb 10, 2021
82e7647
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Feb 11, 2021
6d8f1c2
remove comment about binary body params in multi media types
iscai-msft Feb 11, 2021
03c7b73
fix pylint
iscai-msft Feb 11, 2021
b8442ef
main operation passes url to request
iscai-msft Feb 11, 2021
8655bb4
serialize obj bodies before passing to request
iscai-msft Feb 12, 2021
1482c2b
fix so ops with one media type serialize body in main op
iscai-msft Feb 12, 2021
586f525
remove unnecessary content type inspection
iscai-msft Feb 12, 2021
7a6fb4b
don't serialize constant bodies in main op, serialize in request
iscai-msft Feb 12, 2021
4e6ec75
remove constant bodies from request
iscai-msft Feb 17, 2021
f31bbe4
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Feb 24, 2021
c6d8525
request -> preparer
iscai-msft Feb 24, 2021
21ef574
request parameters to preparer parameters
iscai-msft Feb 24, 2021
0da4930
remove serialization of constant bodies in preparer
iscai-msft Feb 26, 2021
2d899d9
move preparers to protocol namespace (#902)
iscai-msft Mar 16, 2021
3b1e933
make next paging requests public
iscai-msft Mar 16, 2021
ab2f103
remove _request from preparer name
iscai-msft Mar 17, 2021
4b0df76
switch to protocol httprequest and httpresponse (#903)
iscai-msft Mar 19, 2021
7e810aa
add low-level-client flag
iscai-msft Mar 22, 2021
82c6da3
keep convenience layer working
iscai-msft Mar 23, 2021
48a4f0a
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Mar 23, 2021
8d3fb4c
add 'johan' flag
iscai-msft Mar 23, 2021
57d39fc
remove protocol and _protocol layers
iscai-msft Mar 23, 2021
089099b
add examples to send_request docstring
iscai-msft Mar 23, 2021
5e30834
add preparer docstrings
iscai-msft Mar 23, 2021
66df441
add preparer docstrings
iscai-msft Mar 24, 2021
813d39f
temp
iscai-msft Mar 24, 2021
bbe680f
sort out different body kwargs
iscai-msft Mar 24, 2021
fa8d7c2
gen multiple body params, works for llc
iscai-msft Mar 24, 2021
e5bcdb7
add content type tests
iscai-msft Mar 25, 2021
feae12d
add stream checkign request
iscai-msft Mar 26, 2021
62953b7
improve convenience layer generation for multiple media types + docst…
iscai-msft Mar 26, 2021
8fbf9cf
correct keyword docstrings to keyword and paramtype
iscai-msft Mar 26, 2021
d7b292d
preparer -> request builder
iscai-msft Mar 26, 2021
f74c668
fix ordering of method to be params then kwargs
iscai-msft Mar 26, 2021
d9bee54
make body kwargs optional
iscai-msft Mar 26, 2021
cda8703
url
iscai-msft Mar 26, 2021
825bf80
get internal request in send_request
iscai-msft Mar 30, 2021
e74e3dd
add most of vanilla test suite
iscai-msft Mar 30, 2021
1e987f0
always generate serializer
iscai-msft Apr 5, 2021
1dce813
add vendor flag
iscai-msft Apr 5, 2021
e2ba64a
Merge branch 'prepare_request' of https://github.com/Azure/autorest.p…
iscai-msft Apr 5, 2021
68b2e5c
add streaming
iscai-msft Apr 7, 2021
f449582
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Apr 8, 2021
0a71bec
temp
iscai-msft Apr 8, 2021
d39ea93
temp
iscai-msft Apr 14, 2021
0276805
move operation group name to submodule of rest
iscai-msft Apr 15, 2021
8b51709
do reading inside send_request
iscai-msft Apr 16, 2021
4a8dedd
generate with new rest structure and start fixing tests
iscai-msft Apr 19, 2021
68f4da3
temp
iscai-msft Apr 20, 2021
dcbe84d
start azure llc tests
iscai-msft Apr 20, 2021
9d70b30
clean up code
iscai-msft Apr 23, 2021
bb3837e
switch to passing pipeline to stream context manager
iscai-msft Apr 23, 2021
624a5e7
temp
iscai-msft Apr 26, 2021
009713e
generate with response json output template
iscai-msft Apr 28, 2021
f2329b0
no models
iscai-msft Apr 29, 2021
8505ff2
work on connection between convenience layer + rest layer
iscai-msft Apr 29, 2021
b028893
get farmbeats working
iscai-msft Apr 30, 2021
bc1bbfc
improve json input template
iscai-msft May 3, 2021
df21b4d
improve json templating
iscai-msft May 4, 2021
53d73bd
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft May 4, 2021
0d72b79
temp
iscai-msft May 7, 2021
dff7fb1
rename llc aka link
iscai-msft May 11, 2021
b085c97
improve serializers
iscai-msft May 12, 2021
70fd3b5
fix lro paging generation
iscai-msft May 12, 2021
6de4c82
change test generation
iscai-msft May 12, 2021
843bea3
Merge branch 'improve_serializers' of https://github.com/Azure/autore…
iscai-msft May 12, 2021
602e240
move template code to serializers
iscai-msft May 13, 2021
b97532e
add serializers
iscai-msft Jun 1, 2021
c063011
temp
iscai-msft Jun 7, 2021
ba50ed8
most vanilla passing
iscai-msft Jun 7, 2021
b3cb391
temp
iscai-msft Jun 10, 2021
37580b8
temp to generate synapse
iscai-msft Jun 16, 2021
3a5efc4
temp
iscai-msft Jun 21, 2021
78aef80
sync vanilla passing besides formdata
iscai-msft Jun 22, 2021
26630dd
switch _rest to rest
iscai-msft Jun 23, 2021
608ad98
make llc and legacy sections of vanilla test
iscai-msft Jun 23, 2021
50dc877
make send_request in async without async def
iscai-msft Jun 24, 2021
3328993
make async send_request not have async function header, regenerated v…
iscai-msft Jun 25, 2021
b0edf6c
make azure legacy folder, all but storage generating
iscai-msft Jun 29, 2021
d97bc6e
vanilla llc passing
iscai-msft Jul 6, 2021
ed9270a
temp
iscai-msft Jul 6, 2021
77b1d62
azure tests passing
iscai-msft Jul 6, 2021
a8115b6
switch make_request fixture to send_request
iscai-msft Jul 7, 2021
98c9ea5
temp
iscai-msft Jul 8, 2021
edca270
all azure vanilla tests passing
iscai-msft Jul 8, 2021
b559dc5
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Jul 8, 2021
6e65899
revert multiapi to version in autorestv3 branch
iscai-msft Jul 8, 2021
fbda5bf
multiapi generating
iscai-msft Jul 8, 2021
12bca7d
Disable LLC and M4 conflicts
lmazuel Jul 8, 2021
a061c91
regen without PipelineTransportHttpRequest import
iscai-msft Jul 8, 2021
3cbc5b8
regen with new show flags
iscai-msft Jul 8, 2021
1e602c4
improve send_request docstring, allow send_request to be private
iscai-msft Jul 8, 2021
b7b73d8
regen
iscai-msft Jul 9, 2021
c0965d4
fix whitespace
iscai-msft Jul 9, 2021
9046573
lint and mypy wip
iscai-msft Jul 9, 2021
12bef9d
Merge branch 'llc_m4_flags' of https://github.com/Azure/autorest.pyth…
iscai-msft Jul 9, 2021
eb7b77d
regenerate without flattening
iscai-msft Jul 12, 2021
5587303
generate and run llc update tests
iscai-msft Jul 12, 2021
a48bc81
regenerate all again without flattening / grouping
iscai-msft Jul 12, 2021
c244152
lint and mypy
iscai-msft Jul 12, 2021
03aed7b
add llc steps
iscai-msft Jul 12, 2021
6abe67d
fix circular imports
iscai-msft Jul 12, 2021
45b4ee1
fix unittests
iscai-msft Jul 12, 2021
c8c929f
add tox for update tests, move tox.ini for legacy and llc
iscai-msft Jul 12, 2021
940898e
fix generation of json templates
iscai-msft Jul 12, 2021
4d8e09d
don't generate templates if not exposing rest layer
iscai-msft Jul 12, 2021
d45a845
fix missing http_response declaration
iscai-msft Jul 12, 2021
be7018e
lint
iscai-msft Jul 12, 2021
9b2ce27
switch to testing 3.6 instead of 3.5
iscai-msft Jul 12, 2021
70e0dbc
fix testserver starting in conftest
iscai-msft Jul 12, 2021
cc0123f
fix azure llc testserver starting
iscai-msft Jul 12, 2021
6b9eaf3
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Jul 12, 2021
9e6383d
remove vendor flag
iscai-msft Jul 12, 2021
64cf1ca
fix param grouping tests
iscai-msft Jul 13, 2021
4fc2f1a
add model flattening tests
iscai-msft Jul 13, 2021
2130ab0
fix send_request tests in legacy
iscai-msft Jul 13, 2021
9901ce6
fix flag and update changelog
iscai-msft Jul 13, 2021
b29fcfc
fix param groupign tests
iscai-msft Jul 13, 2021
2b4e52e
add coverage for LLC update tests
iscai-msft Jul 13, 2021
75e5371
try vanilla llc coverage
iscai-msft Jul 13, 2021
5e8b87e
pylint
iscai-msft Jul 13, 2021
11339e3
add coverage for llc
iscai-msft Jul 13, 2021
61409d9
don't black generic request builder file bc of trailing comma
iscai-msft Jul 13, 2021
3236278
fix lro test call to correct request
iscai-msft Jul 13, 2021
803e9cc
remove unnecessary ParameterType typevar
iscai-msft Jul 13, 2021
caae78b
pylint
iscai-msft Jul 13, 2021
e801651
add conftest in each acceptance tests folder vanilla llc
iscai-msft Jul 13, 2021
55fbdb3
fix relative path to testserver in vanilla conftests
iscai-msft Jul 13, 2021
51f578c
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python…
iscai-msft Jul 13, 2021
1e70958
pad private variables for LLC
iscai-msft Jul 14, 2021
067d76e
add llc param grouping with reserved word test
iscai-msft Jul 14, 2021
8235624
don't force flags in llc mode
iscai-msft Jul 14, 2021
c6c1011
make fixes after talking with laurent
iscai-msft Jul 14, 2021
c8569cd
skip all llc coverage in legacy tests
iscai-msft Jul 14, 2021
d3a7e0c
fix pylint
iscai-msft Jul 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Change Log

### 2021-xx-xx - 5.9.0

| Library | Min Version
| --------------- | -------
|`@autorest/core` | `3.4.5`
|`@autorest/modelerfour` | `4.19.1`
|`azure-core` dep of generated code | `1.16.0`
|`msrest` dep of generated code | `0.6.21`
|`azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.2.1`

**New Features**

- We have added a **provisional** `rest` layer to our generated code. We have also added the following **provisional** flags listed [here](https://github.com/Azure/autorest.python/wiki/Generating-Low-Level-Client#generate-a-low-level-client). #875
- With this new release, we are also dropping support for Python 3.5 + async. #875

### 2021-07-13 - 5.8.4

min Autorest core version: 3.4.5
Expand Down
83 changes: 61 additions & 22 deletions autorest/codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from .models import build_schema
from .models.operation_group import OperationGroup
from .models.parameter import Parameter
from .models.parameter_list import ParameterList
from .models.parameter_list import GlobalParameterList
from .models.rest import Rest
from .serializers import JinjaSerializer


Expand All @@ -24,6 +25,26 @@ def _get_credential_default_policy_type_has_async_version(credential_default_pol
}
return mapping[credential_default_policy_type]

def _build_convenience_layer(yaml_data: Dict[str, Any], code_model: CodeModel) -> None:
# Create operations
if code_model.show_operations and yaml_data.get("operationGroups"):
code_model.operation_groups = [
OperationGroup.from_yaml(code_model, op_group) for op_group in yaml_data["operationGroups"]
]
if code_model.show_models and yaml_data.get("schemas"):
# sets the enums property in our code_model variable, which will later be passed to EnumSerializer

code_model.add_inheritance_to_models()
code_model.sort_schemas()
code_model.link_operation_to_request_builder()
code_model.add_schema_link_to_operation()
code_model.generate_single_parameter_from_multiple_media_types_operation()

if code_model.show_operations:
# LRO operation
code_model.format_lro_operations()
code_model.remove_next_operation()

_LOGGER = logging.getLogger(__name__)
class CodeGenerator(Plugin):
@staticmethod
Expand Down Expand Up @@ -61,17 +82,44 @@ def _build_exceptions_set(yaml_data: List[Dict[str, Any]]) -> Set[int]:

def _create_code_model(self, yaml_data: Dict[str, Any], options: Dict[str, Union[str, bool]]) -> CodeModel:
# Create a code model
code_model = CodeModel(options)
low_level_client = self._autorestapi.get_boolean_value("low-level-client", False)
show_models = self._autorestapi.get_boolean_value(
"show-models",
not low_level_client
)
show_builders = self._autorestapi.get_boolean_value(
"show-builders",
low_level_client
)
show_operations = self._autorestapi.get_boolean_value(
"show-operations",
not low_level_client
)
show_send_request = self._autorestapi.get_boolean_value(
"show-send-request",
low_level_client
)
only_path_and_body_params_positional = self._autorestapi.get_boolean_value(
"only-path-and-body-params-positional",
low_level_client
)
code_model = CodeModel(
show_builders=show_builders,
show_models=show_models,
show_operations=show_operations,
show_send_request=show_send_request,
only_path_and_body_params_positional=only_path_and_body_params_positional,
options=options,
)
code_model.module_name = yaml_data["info"]["python_title"]
code_model.class_name = yaml_data["info"]["pascal_case_title"]
code_model.description = (
yaml_data["info"]["description"] if yaml_data["info"].get("description") else ""
)

# Global parameters
code_model.global_parameters = ParameterList(
code_model.global_parameters = GlobalParameterList(
[Parameter.from_yaml(param) for param in yaml_data.get("globalParameters", [])],
implementation="Client",
)

# Custom URL
Expand All @@ -82,17 +130,13 @@ def _create_code_model(self, yaml_data: Dict[str, Any], options: Dict[str, Union
# UGLY as hell.....
if yaml_data.get("operationGroups"):
first_req_of_first_op_of_first_grp = yaml_data["operationGroups"][0]["operations"][0]["requests"][0]
code_model.custom_base_url = first_req_of_first_op_of_first_grp["protocol"]["http"]["uri"]
code_model.service_client.custom_base_url = (
first_req_of_first_op_of_first_grp["protocol"]["http"]["uri"]
)
else:
for host in dollar_host:
code_model.global_parameters.remove(host)
code_model.base_url = dollar_host[0].yaml_data["clientDefaultValue"]

# Create operations
if yaml_data.get("operationGroups"):
code_model.operation_groups = [
OperationGroup.from_yaml(code_model, op_group) for op_group in yaml_data["operationGroups"]
]
code_model.service_client.base_url = dollar_host[0].yaml_data["clientDefaultValue"]

# Get my namespace
namespace = self._autorestapi.get_value("namespace")
Expand All @@ -101,23 +145,17 @@ def _create_code_model(self, yaml_data: Dict[str, Any], options: Dict[str, Union
namespace = yaml_data["info"]["python_title"]
code_model.namespace = namespace

code_model.rest = Rest.from_yaml(yaml_data, code_model=code_model)
if yaml_data.get("schemas"):
exceptions_set = CodeGenerator._build_exceptions_set(yaml_data=yaml_data["operationGroups"])

for type_list in yaml_data["schemas"].values():
for schema in type_list:
build_schema(yaml_data=schema, exceptions_set=exceptions_set, code_model=code_model)
# sets the enums property in our code_model variable, which will later be passed to EnumSerializer

code_model.add_inheritance_to_models()
code_model.sort_schemas()
code_model.add_schema_link_to_operation()
code_model.add_schema_link_to_request_builder()
code_model.add_schema_link_to_global_parameters()
code_model.generate_single_parameter_from_multiple_media_types()

# LRO operation
code_model.format_lro_operations()
code_model.remove_next_operation()
_build_convenience_layer(yaml_data=yaml_data, code_model=code_model)

if options["credential"]:
code_model.add_credential_global_parameter()
Expand Down Expand Up @@ -247,7 +285,8 @@ def _build_code_model_options(self) -> Dict[str, Any]:
"credential_default_policy_type": credential_default_policy_type,
"credential_default_policy_type_has_async_version": (
_get_credential_default_policy_type_has_async_version(credential_default_policy_type)
)
),
"polymorphic_examples": self._autorestapi.get_value("polymorphic-examples") or 5,
}

if options["basic_setup_py"] and not options["package_version"]:
Expand Down
39 changes: 34 additions & 5 deletions autorest/codegen/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from typing import Any, Dict
from typing import Any, Dict, TypeVar, Union
from .base_model import BaseModel
from .code_model import CodeModel
from .credential_schema import AzureKeyCredentialSchema, TokenCredentialSchema
Expand All @@ -22,8 +22,13 @@
from .property import Property
from .operation_group import OperationGroup
from .schema_response import SchemaResponse
from .parameter_list import ParameterList

from .parameter_list import GlobalParameterList, ParameterList
from .request_builder_parameter_list import RequestBuilderParameterList
from .request_builder import RequestBuilder
from .base_builder import BaseBuilder
from .lro_paging_operation import LROPagingOperation
from .request_builder_parameter import RequestBuilderParameter
from .schema_request import SchemaRequest

__all__ = [
"AzureKeyCredentialSchema",
Expand All @@ -47,8 +52,13 @@
"ParameterList",
"OperationGroup",
"Property",
"RequestBuilder",
"SchemaResponse",
"TokenCredentialSchema",
"LROPagingOperation",
"BaseBuilder",
"SchemaRequest",
"RequestBuilderParameter",
]

def _generate_as_object_schema(yaml_data: Dict[str, Any]) -> bool:
Expand Down Expand Up @@ -90,7 +100,7 @@ def build_schema(yaml_data: Dict[str, Any], **kwargs) -> BaseSchema:
schema = DictionarySchema.from_yaml(namespace=namespace, yaml_data=yaml_data, **kwargs)
code_model.primitives[yaml_id] = schema

elif schema_type in ["object", "and", "group"]:
elif schema_type in ["object", "and", "group", "any-object"]:
if _generate_as_object_schema(yaml_data):
# To avoid infinite loop, create the right instance in memory,
# put it in the index, and then parse the object.
Expand All @@ -100,9 +110,28 @@ def build_schema(yaml_data: Dict[str, Any], **kwargs) -> BaseSchema:
else:
schema = AnySchema.from_yaml(namespace=namespace, yaml_data=yaml_data)
code_model.primitives[yaml_id] = schema

else:
schema = get_primitive_schema(namespace=namespace, yaml_data=yaml_data)
code_model.primitives[yaml_id] = schema

return schema

BuilderType = TypeVar(
"BuilderType",
bound=Union[
RequestBuilder,
Operation,
LROPagingOperation,
LROOperation,
PagingOperation,
]
)

ParameterListType = TypeVar(
"ParameterListType",
bound=Union[
ParameterList,
GlobalParameterList,
RequestBuilderParameterList,
],
)
96 changes: 96 additions & 0 deletions autorest/codegen/models/base_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from typing import Any, Callable, Dict, List, Optional, Union, TYPE_CHECKING
from abc import abstractmethod
from .base_model import BaseModel
from .schema_response import SchemaResponse

if TYPE_CHECKING:
from . import ParameterListType


_M4_HEADER_PARAMETERS = ["content_type", "accept"]

def get_converted_parameters(yaml_data: Dict[str, Any], parameter_converter: Callable):
multiple_requests = len(yaml_data["requests"]) > 1

multiple_media_type_parameters = []
parameters = [parameter_converter(yaml) for yaml in yaml_data.get("parameters", [])]

for request in yaml_data["requests"]:
for yaml in request.get("parameters", []):
parameter = parameter_converter(yaml)
name = yaml["language"]["python"]["name"]
if name in _M4_HEADER_PARAMETERS:
parameters.append(parameter)
elif multiple_requests:
parameter.has_multiple_media_types = True
multiple_media_type_parameters.append(parameter)
else:
parameters.append(parameter)

if multiple_media_type_parameters:
body_parameters_name_set = set(
p.serialized_name for p in multiple_media_type_parameters
)
if len(body_parameters_name_set) > 1:
raise ValueError(
f"The body parameter with multiple media types has different names: {body_parameters_name_set}"
)


parameters_index = {id(parameter.yaml_data): parameter for parameter in parameters}

# Need to connect the groupBy and originalParameter
for parameter in parameters:
parameter_grouped_by_id = id(parameter.grouped_by)
if parameter_grouped_by_id in parameters_index:
parameter.grouped_by = parameters_index[parameter_grouped_by_id]

parameter_original_id = id(parameter.original_parameter)
if parameter_original_id in parameters_index:
parameter.original_parameter = parameters_index[parameter_original_id]

return parameters, multiple_media_type_parameters

class BaseBuilder(BaseModel):
"""Base class for Operations and Request Builders"""

def __init__(
self,
yaml_data: Dict[str, Any],
name: str,
description: str,
parameters: "ParameterListType",
responses: Optional[List[SchemaResponse]] = None,
summary: Optional[str] = None,
) -> None:
super().__init__(yaml_data=yaml_data)
self.name = name
self.description = description
self.parameters = parameters
self.responses = responses or []
self.summary = summary

@property
def default_content_type_declaration(self) -> str:
return f'"{self.parameters.default_content_type}"'

def get_response_from_status(self, status_code: int) -> SchemaResponse:
for response in self.responses:
if status_code in response.status_codes:
return response
raise ValueError(f"Incorrect status code {status_code}, operation {self.name}")

@property
def success_status_code(self) -> List[Union[str, int]]:
"""The list of all successfull status code."""
return [code for response in self.responses for code in response.status_codes if code != "default"]

@staticmethod
@abstractmethod
def get_parameter_converter() -> Callable:
...
13 changes: 11 additions & 2 deletions autorest/codegen/models/base_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def has_xml_serialization_ctxt(self) -> bool:
return bool(self.xml_metadata)

def xml_serialization_ctxt(self) -> Optional[str]:
"""Return the serialization context in case this schema is used in an operation.
"""
"""Return the serialization context in case this schema is used in an operation."""
attrs_list = []
if self.xml_metadata.get("name"):
attrs_list.append(f"'name': '{self.xml_metadata['name']}'")
Expand Down Expand Up @@ -127,3 +126,13 @@ def validation_map(self) -> Optional[Dict[str, Union[bool, int, str]]]: # pylin
@property
def serialization_constraints(self) -> Optional[List[str]]: # pylint: disable=no-self-use
return None

@abstractmethod
def get_json_template_representation(self, **kwargs: Any) -> Any:
"""Template of what this schema would look like as JSON input"""
...

@abstractmethod
def get_files_template_representation(self, **kwargs: Any) -> Any:
"""Template of what this schema would look like as files input"""
...
Loading