@autorest/python 5.14.0 → 5.17.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.
Files changed (120) hide show
  1. package/ChangeLog.md +91 -2
  2. package/README.md +30 -4
  3. package/autorest/__init__.py +2 -3
  4. package/autorest/black/__init__.py +12 -5
  5. package/autorest/codegen/__init__.py +130 -179
  6. package/autorest/codegen/models/__init__.py +122 -78
  7. package/autorest/codegen/models/base_builder.py +70 -72
  8. package/autorest/codegen/models/base_model.py +7 -5
  9. package/autorest/codegen/models/{base_schema.py → base_type.py} +62 -49
  10. package/autorest/codegen/models/client.py +195 -36
  11. package/autorest/codegen/models/code_model.py +165 -299
  12. package/autorest/codegen/models/combined_type.py +107 -0
  13. package/autorest/codegen/models/constant_type.py +122 -0
  14. package/autorest/codegen/models/credential_types.py +224 -0
  15. package/autorest/codegen/models/dictionary_type.py +116 -0
  16. package/autorest/codegen/models/enum_type.py +195 -0
  17. package/autorest/codegen/models/imports.py +95 -41
  18. package/autorest/codegen/models/list_type.py +134 -0
  19. package/autorest/codegen/models/lro_operation.py +90 -133
  20. package/autorest/codegen/models/lro_paging_operation.py +28 -12
  21. package/autorest/codegen/models/model_type.py +239 -0
  22. package/autorest/codegen/models/operation.py +415 -241
  23. package/autorest/codegen/models/operation_group.py +82 -88
  24. package/autorest/codegen/models/paging_operation.py +101 -117
  25. package/autorest/codegen/models/parameter.py +307 -322
  26. package/autorest/codegen/models/parameter_list.py +366 -357
  27. package/autorest/codegen/models/primitive_types.py +544 -0
  28. package/autorest/codegen/models/property.py +122 -134
  29. package/autorest/codegen/models/request_builder.py +138 -86
  30. package/autorest/codegen/models/request_builder_parameter.py +122 -79
  31. package/autorest/codegen/models/response.py +325 -0
  32. package/autorest/codegen/models/utils.py +17 -1
  33. package/autorest/codegen/serializers/__init__.py +242 -118
  34. package/autorest/codegen/serializers/builder_serializer.py +863 -1027
  35. package/autorest/codegen/serializers/client_serializer.py +148 -82
  36. package/autorest/codegen/serializers/general_serializer.py +44 -47
  37. package/autorest/codegen/serializers/import_serializer.py +96 -31
  38. package/autorest/codegen/serializers/metadata_serializer.py +39 -79
  39. package/autorest/codegen/serializers/model_base_serializer.py +65 -29
  40. package/autorest/codegen/serializers/model_generic_serializer.py +9 -10
  41. package/autorest/codegen/serializers/model_init_serializer.py +4 -2
  42. package/autorest/codegen/serializers/model_python3_serializer.py +29 -22
  43. package/autorest/codegen/serializers/operation_groups_serializer.py +21 -18
  44. package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
  45. package/autorest/codegen/serializers/parameter_serializer.py +174 -0
  46. package/autorest/codegen/serializers/patch_serializer.py +14 -2
  47. package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
  48. package/autorest/codegen/serializers/utils.py +0 -103
  49. package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
  50. package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
  51. package/autorest/codegen/templates/config.py.jinja2 +13 -13
  52. package/autorest/codegen/templates/enum.py.jinja2 +4 -4
  53. package/autorest/codegen/templates/enum_container.py.jinja2 +1 -2
  54. package/autorest/codegen/templates/init.py.jinja2 +9 -6
  55. package/autorest/codegen/templates/keywords.jinja2 +14 -1
  56. package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
  57. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
  58. package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
  59. package/autorest/codegen/templates/model.py.jinja2 +23 -29
  60. package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
  61. package/autorest/codegen/templates/model_init.py.jinja2 +9 -8
  62. package/autorest/codegen/templates/operation.py.jinja2 +10 -15
  63. package/autorest/codegen/templates/operation_group.py.jinja2 +14 -13
  64. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -2
  65. package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
  66. package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
  67. package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
  68. package/autorest/codegen/templates/patch.py.jinja2 +18 -29
  69. package/autorest/codegen/templates/request_builder.py.jinja2 +20 -13
  70. package/autorest/codegen/templates/setup.py.jinja2 +9 -3
  71. package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
  72. package/autorest/jsonrpc/__init__.py +7 -12
  73. package/autorest/jsonrpc/localapi.py +4 -3
  74. package/autorest/jsonrpc/server.py +28 -9
  75. package/autorest/jsonrpc/stdstream.py +13 -6
  76. package/autorest/m2r/__init__.py +5 -8
  77. package/autorest/m4reformatter/__init__.py +1108 -0
  78. package/autorest/multiapi/__init__.py +24 -14
  79. package/autorest/multiapi/models/client.py +21 -11
  80. package/autorest/multiapi/models/code_model.py +23 -10
  81. package/autorest/multiapi/models/config.py +4 -1
  82. package/autorest/multiapi/models/constant_global_parameter.py +1 -0
  83. package/autorest/multiapi/models/global_parameter.py +2 -1
  84. package/autorest/multiapi/models/global_parameters.py +14 -8
  85. package/autorest/multiapi/models/imports.py +35 -18
  86. package/autorest/multiapi/models/mixin_operation.py +5 -5
  87. package/autorest/multiapi/models/operation_group.py +2 -1
  88. package/autorest/multiapi/models/operation_mixin_group.py +21 -10
  89. package/autorest/multiapi/serializers/__init__.py +20 -25
  90. package/autorest/multiapi/serializers/import_serializer.py +47 -15
  91. package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
  92. package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
  93. package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
  94. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
  95. package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
  96. package/autorest/multiapi/utils.py +3 -3
  97. package/autorest/postprocess/__init__.py +202 -0
  98. package/autorest/postprocess/get_all.py +19 -0
  99. package/autorest/postprocess/venvtools.py +73 -0
  100. package/autorest/preprocess/__init__.py +209 -0
  101. package/autorest/preprocess/helpers.py +54 -0
  102. package/autorest/{namer → preprocess}/python_mappings.py +25 -32
  103. package/package.json +3 -3
  104. package/run-python3.js +2 -3
  105. package/venvtools.py +1 -1
  106. package/autorest/codegen/models/constant_schema.py +0 -97
  107. package/autorest/codegen/models/credential_schema.py +0 -90
  108. package/autorest/codegen/models/credential_schema_policy.py +0 -77
  109. package/autorest/codegen/models/dictionary_schema.py +0 -103
  110. package/autorest/codegen/models/enum_schema.py +0 -246
  111. package/autorest/codegen/models/list_schema.py +0 -113
  112. package/autorest/codegen/models/object_schema.py +0 -249
  113. package/autorest/codegen/models/primitive_schemas.py +0 -476
  114. package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
  115. package/autorest/codegen/models/rest.py +0 -42
  116. package/autorest/codegen/models/schema_request.py +0 -45
  117. package/autorest/codegen/models/schema_response.py +0 -123
  118. package/autorest/codegen/serializers/rest_serializer.py +0 -57
  119. package/autorest/namer/__init__.py +0 -25
  120. package/autorest/namer/name_converter.py +0 -412
@@ -11,32 +11,32 @@
11
11
  VERSION = "unknown"
12
12
  {% endif %}
13
13
 
14
- class {{ code_model.class_name }}Configuration(Configuration): # pylint: disable=too-many-instance-attributes
15
- """Configuration for {{ code_model.class_name }}.
14
+ class {{ code_model.client.name }}Configuration(Configuration): # pylint: disable=too-many-instance-attributes
15
+ """Configuration for {{ code_model.client.name }}.
16
16
 
17
17
  Note that all parameters used to create this instance are saved as instance
18
18
  attributes.
19
- {% if code_model.global_parameters.config_method | first %}
19
+ {% if code_model.config.parameters.method | first %}
20
20
 
21
21
  {% endif %}
22
- {{ op_tools.serialize_with_wrap(serializer.property_descriptions(), "\n ") | indent }}
22
+ {{ op_tools.serialize_with_wrap(serializer.property_descriptions(async_mode), "\n ") | indent }}
23
23
  {{ serializer.init_signature_and_response_type_annotation(async_mode) | indent }}
24
- super({{ code_model.class_name }}Configuration, self).__init__(**kwargs)
25
- {% if code_model.service_client.parameters.config_kwargs_to_pop(async_mode) %}
24
+ super({{ code_model.client.name }}Configuration, self).__init__(**kwargs)
25
+ {% if code_model.config.parameters.kwargs_to_pop(async_mode) %}
26
26
  {{ op_tools.serialize(serializer.pop_kwargs_from_signature(async_mode)) | indent(8) }}
27
27
  {% endif %}
28
28
  {% if serializer.check_required_parameters() %}
29
29
  {{ op_tools.serialize(serializer.check_required_parameters()) | indent(8) -}}
30
30
  {% endif %}
31
31
 
32
- {% for parameter in code_model.global_parameters.config_method %}
33
- self.{{ parameter.serialized_name }} = {{ parameter.serialized_name }}
32
+ {% for parameter in code_model.config.parameters.method %}
33
+ self.{{ parameter.client_name }} = {{ parameter.client_name }}
34
34
  {% endfor %}
35
35
  {% if serializer.set_constants() %}
36
36
  {{ op_tools.serialize(serializer.set_constants()) | indent(8) -}}
37
37
  {% endif %}
38
- {% if code_model.options['credential'] and code_model.credential_schema_policy.credential_scopes is defined %}
39
- self.credential_scopes = kwargs.pop('credential_scopes', {{ code_model.credential_schema_policy.credential_scopes }})
38
+ {% if code_model.credential and code_model.credential.type.policy.credential_scopes is defined %}
39
+ self.credential_scopes = kwargs.pop('credential_scopes', {{ code_model.credential.type.policy.credential_scopes }})
40
40
  {% endif %}
41
41
  kwargs.setdefault('sdk_moniker', '{{ sdk_moniker }}/{}'.format(VERSION))
42
42
  self._configure(**kwargs)
@@ -57,12 +57,12 @@ class {{ code_model.class_name }}Configuration(Configuration): # pylint: disabl
57
57
  self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
58
58
  self.redirect_policy = kwargs.get('redirect_policy') or policies.{{ keywords.async_class }}RedirectPolicy(**kwargs)
59
59
  self.authentication_policy = kwargs.get('authentication_policy')
60
- {% if code_model.options['credential'] %}
60
+ {% if code_model.credential %}
61
61
  {# only adding this if credential_scopes is not passed during code generation #}
62
- {% if code_model.credential_schema_policy.credential_scopes is defined and code_model.credential_schema_policy.credential_scopes|length == 0 %}
62
+ {% if code_model.credential.type.policy.credential_scopes is defined and code_model.credential.type.policy.credential_scopes | length == 0 %}
63
63
  if not self.credential_scopes and not self.authentication_policy:
64
64
  raise ValueError("You must provide either credential_scopes or authentication_policy as kwargs")
65
65
  {% endif %}
66
66
  if self.credential and not self.authentication_policy:
67
- self.authentication_policy = {{ code_model.credential_schema_policy.call(async_mode) }}
67
+ self.authentication_policy = {{ code_model.credential.type.policy.call(async_mode) }}
68
68
  {% endif %}
@@ -1,7 +1,7 @@
1
1
 
2
- class {{ enum.name }}(with_metaclass(CaseInsensitiveEnumMeta, {{ enum.enum_type.type_annotation }}, Enum)):
3
- {% if enum.description %}
4
- """{{ enum.description | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
2
+ class {{ enum.name }}({{ enum.value_type.type_annotation(is_operation_file=False) }}, Enum, metaclass=CaseInsensitiveEnumMeta):
3
+ {% if enum.yaml_data.get("description") %}
4
+ """{{ enum.yaml_data["description"] | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
5
5
  """
6
6
  {% endif %}
7
7
 
@@ -9,5 +9,5 @@ class {{ enum.name }}(with_metaclass(CaseInsensitiveEnumMeta, {{ enum.enum_type.
9
9
  {% if value.description %}
10
10
  #: {{ value.description | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n #: ') }}
11
11
  {% endif %}
12
- {{ value.name }} = {{ enum.enum_type.get_declaration(value.value) }}
12
+ {{ value.name }} = {{ enum.value_type.get_declaration(value.value) }}
13
13
  {% endfor %}
@@ -2,9 +2,8 @@
2
2
  {{ code_model.options['license_header'] }}
3
3
 
4
4
  from enum import Enum
5
- from six import with_metaclass
6
5
  from azure.core import CaseInsensitiveEnumMeta
7
6
 
8
- {% for enum in code_model.enums.values() | sort %}
7
+ {% for enum in code_model.enums | sort %}
9
8
  {% include "enum.py.jinja2" %}
10
9
  {% endfor %}
@@ -1,15 +1,18 @@
1
+ {% import 'keywords.jinja2' as keywords %}
1
2
  # coding=utf-8
2
3
  {{ code_model.options['license_header'] }}
3
4
 
4
- from ._{{ code_model.module_name }} import {{ code_model.class_name }}
5
+ {% if code_model.request_builders %}
6
+ from .{{ code_model.client.filename }} import {{ code_model.client.name }}
7
+ {% endif %}
5
8
  {% if not async_mode and code_model.options['package_version']%}
6
9
  from ._version import VERSION
7
10
 
8
11
  __version__ = VERSION
9
12
  {% endif %}
10
- __all__ = ['{{ code_model.class_name }}']
11
13
 
12
- # `._patch.py` is used for handwritten extensions to the generated code
13
- # Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
14
- from ._patch import patch_sdk
15
- patch_sdk()
14
+ {{ keywords.patch_imports(try_except=True) }}
15
+ __all__ = [{{("'" + code_model.client.name + "'") if code_model.request_builders else ""}}]
16
+ {{ keywords.extend_all }}
17
+
18
+ _patch_sdk()
@@ -3,4 +3,17 @@
3
3
  {% set await = "await " if async_mode else "" %}
4
4
  {% set async_class = "Async" if async_mode else "" %}
5
5
  {% macro escape_str(s) %}'{{ s|replace("'", "\\'") }}'{% endmacro %}
6
- {% set kwargs_declaration = "**kwargs: Any" if async_mode else "**kwargs # type: Any" %}
6
+ {% set kwargs_declaration = "**kwargs: Any" if async_mode else "**kwargs # type: Any" %}
7
+ {% set extend_all = "__all__.extend([p for p in _patch_all if p not in __all__])" %}
8
+ {% macro patch_imports(try_except=False) %}
9
+ {% set indentation = " " if try_except else "" %}
10
+ {% if try_except %}
11
+ try:
12
+ {% endif %}
13
+ {{ indentation }}from ._patch import __all__ as _patch_all
14
+ {{ indentation }}from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import
15
+ {% if try_except %}
16
+ except ImportError:
17
+ _patch_all = []
18
+ {% endif %}
19
+ from ._patch import patch_sdk as _patch_sdk{% endmacro %}
@@ -1,18 +1,19 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools with context %}
2
- {% set trace_decorator = "@distributed_trace_async" if async_mode else "@distributed_trace" %}
3
2
  {# actual template starts here #}
4
- {% if code_model.options['tracing'] %}
5
- {{ trace_decorator }}
3
+ {% if operation.overloads and operation.public %}
4
+ {{ op_tools.generate_overloads(operation_serializer, operation) }}
6
5
  {% endif %}
7
6
  {{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
8
7
  {{ op_tools.description(operation, operation_serializer) | indent -}}
9
- {% if operation.parameters.kwargs_to_pop(async_mode) %}
8
+ {% if not operation.abstract %}
9
+ {% if operation_serializer.pop_kwargs_from_signature(operation) %}
10
10
  {{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
11
- {%- endif %}
11
+ {%- endif %}
12
12
  {{ op_tools.serialize(operation_serializer.initial_call(operation)) | indent }}
13
13
  {{ op_tools.serialize(operation_serializer.get_long_running_output(operation)) | indent }}
14
14
 
15
15
  {{ op_tools.serialize(operation_serializer.return_lro_poller(operation)) | indent }}
16
+ {% endif %}
16
17
  {% if not code_model.options["version_tolerant"] %}
17
18
  {{ operation_serializer.get_metadata_url(operation) -}}
18
19
  {% endif %}
@@ -1,20 +1,21 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools with context %}
2
2
  {% import 'keywords.jinja2' as keywords with context %}
3
- {% set trace_decorator = "@distributed_trace_async" if async_mode else "@distributed_trace" %}
4
3
  {# actual template starts here #}
5
- {% if code_model.options['tracing'] %}
6
- {{ trace_decorator }}
4
+ {% if operation.overloads and operation.public %}
5
+ {{ op_tools.generate_overloads(operation_serializer, operation) }}
7
6
  {% endif %}
8
7
  {{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
9
8
  {{ op_tools.description(operation, operation_serializer) | indent }}
10
- {% if operation.parameters.kwargs_to_pop(async_mode) %}
9
+ {% if not operation.abstract %}
10
+ {% if operation_serializer.pop_kwargs_from_signature(operation) %}
11
11
  {{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
12
- {% endif %}
12
+ {% endif %}
13
13
  {{ op_tools.serialize(operation_serializer.set_up_params_for_pager(operation)) | indent }}
14
14
 
15
15
  {{ op_tools.serialize(operation_serializer.initial_call(operation)) | indent }}
16
16
  {{ op_tools.serialize(operation_serializer.get_long_running_output(operation)) | indent }}
17
17
  {{ op_tools.serialize(operation_serializer.return_lro_poller(operation)) | indent }}
18
+ {% endif %}
18
19
  {% if not code_model.options["version_tolerant"] %}
19
20
  {{ operation_serializer.get_metadata_url(operation) }}
20
21
  {% endif %}
@@ -1,15 +1,15 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools %}
2
2
  {% import 'keywords.jinja2' as keywords %}
3
- {% set service_client = code_model.service_client %}
3
+ {% set client = code_model.client %}
4
4
  {
5
5
  "chosen_version": {{ chosen_version | tojson }},
6
6
  "total_api_version_list": {{ total_api_version_list | tojson }},
7
7
  "client": {
8
- "name": {{ code_model.class_name | tojson }},
8
+ "name": {{ code_model.client.name | tojson }},
9
9
  "filename": {{ ("_" + code_model.module_name) | tojson }},
10
- "description": {{ code_model.description | tojson }},
11
- "host_value": {{ (service_client.parameters.host.default_value_declaration if not service_client.has_parameterized_host else None) | tojson }},
12
- "parameterized_host_template": {{ (keywords.escape_str(service_client.parameterized_host_template) if service_client.has_parameterized_host else None) | tojson }},
10
+ "description": {{ code_model.client.description | tojson }},
11
+ "host_value": {{ (client.parameters.host.client_default_value_declaration if not client.has_parameterized_host else None) | tojson }},
12
+ "parameterized_host_template": {{ (keywords.escape_str(client.url) if client.has_parameterized_host else None) | tojson }},
13
13
  "azure_arm": {{ code_model.options["azure_arm"] | tojson }},
14
14
  "has_lro_operations": {{ code_model.has_lro_operations | tojson }},
15
15
  "client_side_validation": {{ code_model.options["client_side_validation"] | tojson }},
@@ -18,31 +18,31 @@
18
18
  },
19
19
  "global_parameters": {
20
20
  "sync": {
21
- {% for gp in sync_global_parameters.config_method | rejectattr("serialized_name", "equalto", "api_version") %}
22
- {{ gp.serialized_name | tojson }}: {
23
- "signature": {{ gp.method_signature(is_python3_file=False) | tojson }},
21
+ {% for gp in global_parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") %}
22
+ {{ gp.client_name | tojson }}: {
23
+ "signature": {{ gp.method_signature(is_python3_file=False, async_mode=False) | tojson }},
24
24
  "description": {{ gp.description | tojson }},
25
- "docstring_type": {{ gp.docstring_type | tojson }},
26
- "required": {{ gp.required | tojson }}
25
+ "docstring_type": {{ gp.docstring_type(async_mode=False) | tojson }},
26
+ "required": {{ (not gp.optional) | tojson }}
27
27
  }{{ "," if not loop.last else "" }}
28
28
  {% endfor %}
29
29
  },
30
30
  "async": {
31
- {% for gp in async_global_parameters.config_method | rejectattr("serialized_name", "equalto", "api_version") %}
32
- {{ gp.serialized_name | tojson }}: {
33
- "signature": {{ (gp.method_signature(is_python3_file=True)) | tojson }},
31
+ {% for gp in global_parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") %}
32
+ {{ gp.client_name | tojson }}: {
33
+ "signature": {{ (gp.method_signature(is_python3_file=True, async_mode=True)) | tojson }},
34
34
  "description": {{ gp.description | tojson }},
35
- "docstring_type": {{ gp.docstring_type | tojson }},
36
- "required": {{ gp.required | tojson }}
35
+ "docstring_type": {{ gp.docstring_type(async_mode=True) | tojson }},
36
+ "required": {{ (not gp.optional) | tojson }}
37
37
  }{{ "," if not loop.last else "" }}
38
38
  {% endfor %}
39
39
  },
40
40
  "constant": {
41
- {% for gp in code_model.global_parameters.constant | rejectattr("serialized_name", "equalto", "api_version") %}
42
- {{ gp.serialized_name | tojson }}: {{ gp.constant_declaration | tojson }}{{ "," if not loop.last else "" }}
41
+ {% for gp in code_model.client.parameters.constant | rejectattr("client_name", "equalto", "api_version") %}
42
+ {{ gp.client_name | tojson }}: {{ gp.constant_declaration | tojson }}{{ "," if not loop.last else "" }}
43
43
  {% endfor %}
44
44
  },
45
- "call": {{ code_model.global_parameters.config_method | rejectattr("serialized_name", "equalto", "api_version") | map(attribute="serialized_name") | join(', ') | tojson }},
45
+ "call": {{ code_model.client.parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") | map(attribute="client_name") | join(', ') | tojson }},
46
46
  "service_client_specific": {
47
47
  "sync": {
48
48
  "api_version": {
@@ -51,9 +51,9 @@
51
51
  "docstring_type": "str",
52
52
  "required": false
53
53
  },
54
- {% if not service_client.has_parameterized_host %}
54
+ {% if not client.has_parameterized_host %}
55
55
  "base_url": {
56
- "signature": {{ service_client.parameters.host.method_signature(False) | tojson }},
56
+ "signature": {{ client.parameters.host.method_signature(False, async_mode=False) | tojson }},
57
57
  "description": "Service URL",
58
58
  "docstring_type": "str",
59
59
  "required": false
@@ -73,9 +73,9 @@
73
73
  "docstring_type": "str",
74
74
  "required": false
75
75
  },
76
- {% if not service_client.has_parameterized_host %}
76
+ {% if not client.has_parameterized_host %}
77
77
  "base_url": {
78
- "signature": {{ service_client.parameters.host.method_signature(True) | tojson }},
78
+ "signature": {{ client.parameters.host.method_signature(True, async_mode=True) | tojson }},
79
79
  "description": "Service URL",
80
80
  "docstring_type": "str",
81
81
  "required": false
@@ -91,16 +91,16 @@
91
91
  }
92
92
  },
93
93
  "config": {
94
- "credential": {{ code_model.options['credential'] | tojson }},
95
- "credential_scopes": {{ (code_model.credential_schema_policy.credential_scopes if code_model.options['credential'] and code_model.credential_schema_policy.credential_scopes is defined else None)| tojson}},
96
- "credential_call_sync": {{ (code_model.credential_schema_policy.call(async_mode=False) if code_model.options['credential'] else None) | tojson }},
97
- "credential_call_async": {{ (code_model.credential_schema_policy.call(async_mode=True) if code_model.options['credential'] else None) | tojson }},
94
+ "credential": {{ has_credential | tojson }},
95
+ "credential_scopes": {{ (code_model.credential.type.policy.credential_scopes if has_credential and code_model.credential.type.policy.credential_scopes is defined else None)| tojson}},
96
+ "credential_call_sync": {{ (code_model.credential.type.policy.call(async_mode=False) if has_credential else None) | tojson }},
97
+ "credential_call_async": {{ (code_model.credential.type.policy.call(async_mode=True) if has_credential else None) | tojson }},
98
98
  "sync_imports": {{ sync_config_imports | tojson }},
99
99
  "async_imports": {{ async_config_imports | tojson }}
100
100
  },
101
101
  "operation_groups": {
102
- {% for operation_group in code_model.operation_groups | rejectattr('is_empty_operation_group') %}
103
- {{ operation_group.name | tojson }}: {{ operation_group.class_name | tojson }}{{ "," if not loop.last else "" }}
102
+ {% for operation_group in code_model.operation_groups | rejectattr('is_mixin') %}
103
+ {{ operation_group.property_name | tojson }}: {{ operation_group.class_name | tojson }}{{ "," if not loop.last else "" }}
104
104
  {% endfor %}
105
105
  }{{ "," if mixin_operations }}
106
106
  {% if mixin_operations %}
@@ -109,7 +109,7 @@
109
109
  "async_imports": {{ str(async_mixin_imports) | tojson }},
110
110
  "operations": {
111
111
  {% for operation in mixin_operations %}
112
- {{ operation.python_name | tojson }} : {
112
+ {{ operation.name | tojson }} : {
113
113
  {% set request_builder = operation.request_builder %}
114
114
  "sync": {
115
115
  {% set operation_serializer = get_sync_operation_serializer(operation) %}
@@ -126,8 +126,9 @@
126
126
  {% from "operation.py.jinja2" import operation_docstring with context %}
127
127
  {% set sync_return_type_wrapper = "" %}
128
128
  {% endif %}
129
- "signature": {{ (operation_serializer.method_signature_and_response_type_annotation(operation) + "\n") | tojson }},
130
- "doc": {{ op_tools.description(operation, operation_serializer).rstrip("\n") | tojson }}
129
+ "signature": {{ (operation_serializer.method_signature_and_response_type_annotation(operation, want_decorators=False) + "\n") | tojson }},
130
+ "doc": {{ op_tools.description(operation, operation_serializer).rstrip("\n") | tojson }},
131
+ "call": {{ operation.parameters.call | join(', ') | tojson }}
131
132
  },
132
133
  "async": {
133
134
  {% set coroutine = False if (is_paging(operation) and not is_lro(operation)) else True %}
@@ -146,10 +147,10 @@
146
147
  {% from "operation.py.jinja2" import operation_docstring with context %}
147
148
  {% set async_return_type_wrapper = "" %}
148
149
  {% endif %}
149
- "signature": {{ (operation_serializer.method_signature_and_response_type_annotation(operation) + "\n") | tojson }},
150
- "doc": {{ op_tools.description(operation, operation_serializer).rstrip("\n") | tojson }}
151
- },
152
- "call": {{ operation.parameters.method | rejectattr("is_kwarg") | map(attribute="serialized_name") | rejectattr("is_kwarg") | join(', ') | tojson }}
150
+ "signature": {{ (operation_serializer.method_signature_and_response_type_annotation(operation, want_decorators=False) + "\n") | tojson }},
151
+ "doc": {{ op_tools.description(operation, operation_serializer).rstrip("\n") | tojson }},
152
+ "call": {{ operation.parameters.call | join(', ') | tojson }}
153
+ }
153
154
  }{{ "," if not loop.last else "" }}
154
155
  {% endfor %}
155
156
  }
@@ -1,30 +1,24 @@
1
- {% set basename = model.base_models | join(', ', attribute='name') if model.base_models else "" %}
2
1
  {# actual template starts here #}
3
2
 
4
3
 
5
- {% if basename %}
6
- class {{ model.name }}({{ basename }}):
7
- {% else %}
8
- class {{ model.name }}(msrest.serialization.Model):
9
- {% endif %}
10
- """{{ model.description }}
11
- {% if model.discriminator_name %}
4
+ {{ serializer.declare_model(model) }}
5
+ """{{ model.description(is_operation_file=False) }}
6
+ {% if model.discriminated_subtypes %}
12
7
 
13
- You probably want to use the sub-classes and not this class directly. Known
14
- sub-classes are: {{ model.subtype_map.values()|join(', ') }}.
8
+ {{ serializer.discriminator_docstring(model) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
15
9
  {% endif %}
16
10
  {% if model.has_readonly_or_constant_property %}
17
11
 
18
12
  Variables are only populated by the server, and will be ignored when sending a request.
19
13
  {% endif %}
20
- {% if (model.properties | selectattr('required') | first) is defined %}
14
+ {% if (model.properties | selectattr('optional', "equalto", false) | first) is defined %}
21
15
 
22
16
  All required parameters must be populated in order to send to Azure.
23
17
  {% endif %}
24
18
 
25
19
  {% if model.properties != None %}
26
20
  {% for p in model.properties %}
27
- {% for line in variable_documentation_string(p) %}
21
+ {% for line in serializer.variable_documentation_string(p) %}
28
22
  {% for doc_string in line.replace('\n', '\n ').split('\n') %}
29
23
  {{ doc_string | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
30
24
  {% endfor %}
@@ -32,45 +26,44 @@ class {{ model.name }}(msrest.serialization.Model):
32
26
  {% endfor %}
33
27
  {% endif %}
34
28
  """
35
- {% if (model.properties | selectattr('validation_map') ) | first %}
29
+ {% if (model.properties | selectattr('validation') ) | first %}
36
30
 
37
31
  _validation = {
38
- {% for p in model.properties | selectattr('validation_map')%}
39
- '{{ p.name }}': {{ str(p.validation_map) }},
32
+ {% for p in model.properties | selectattr('validation')%}
33
+ '{{ p.client_name }}': {{ str(p.validation) }},
40
34
  {% endfor %}
41
35
  }
42
36
  {% endif %}
43
37
 
44
38
  _attribute_map = {
45
- {% if model.properties != None %}
39
+ {% if model.properties %}
46
40
  {% for p in model.properties %}
47
- '{{ p.name }}': {'key': '{{ p.escaped_swagger_name }}', 'type': '{{ p.serialization_type}}'{{ p.xml_metadata }}},
41
+ {{ p.attribute_map }}
48
42
  {% endfor %}
49
- {% else%}
50
43
  {% endif %}
51
44
  }
52
- {% if model.discriminator_name %}
45
+ {% if model.discriminated_subtypes %}
53
46
 
54
47
  _subtype_map = {
55
- '{{ model.discriminator_name }}': {{ str(model.subtype_map) }}
48
+ '{{ model.discriminator.client_name }}': {{ str(model.discriminated_subtypes) }}
56
49
  }
57
50
  {% endif %}
58
- {% if model.xml_metadata %}
51
+ {% if model.xml_map_content %}
59
52
  _xml_map = {
60
- {{ model.xml_map_content() }}
53
+ {{ model.xml_map_content }}
61
54
  }
62
55
  {% endif %}
63
56
  {% if (model.properties | selectattr('constant') | first) is defined %}
64
57
 
65
58
  {% for p in model.properties | selectattr('constant')%}
66
- {{ p.name }} = {{ p.constant_declaration }}
59
+ {{ p.client_name }} = {{ p.type.get_declaration() }}
67
60
  {% endfor %}
68
61
  {% endif %}
69
62
 
70
- def __init__(
63
+ def __init__({{ model.init_pylint_disable }}
71
64
  self,
72
- {% for param_signature in init_line(model) %}
73
- {{ param_signature }},
65
+ {% for param_signature in serializer.init_line(model) %}
66
+ {{ param_signature }}
74
67
  {% endfor %}
75
68
  **kwargs
76
69
  ):
@@ -78,7 +71,7 @@ class {{ model.name }}(msrest.serialization.Model):
78
71
  {% if model.properties %}
79
72
  {% for p in model.properties %}
80
73
  {% if p.is_input %}
81
- {% for line in input_documentation_string(p) %}
74
+ {% for line in serializer.input_documentation_string(p) %}
82
75
  {% for doc_string in line.replace('\n', '\n ').split('\n') %}
83
76
  {{ doc_string | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
84
77
  {% endfor %}
@@ -87,6 +80,7 @@ class {{ model.name }}(msrest.serialization.Model):
87
80
  {% endfor %}
88
81
  {% endif %}
89
82
  """
90
- {% for arg in init_args(model) %}
91
- {{ arg }}
83
+ {{ serializer.super_call(model) }}
84
+ {% for initialize_property in serializer.initialize_properties(model) %}
85
+ {{ initialize_property }}
92
86
  {% endfor %}
@@ -1,7 +1,8 @@
1
1
  # coding=utf-8
2
+ # pylint: disable=too-many-lines
2
3
  {{ code_model.options['license_header'] }}
3
4
 
4
5
  {{ imports }}
5
- {% for model in code_model.sorted_schemas %}
6
+ {% for model in code_model.model_types %}
6
7
  {% include "model.py.jinja2" %}
7
8
  {% endfor %}
@@ -1,8 +1,9 @@
1
+ {% import 'keywords.jinja2' as keywords %}
1
2
  # coding=utf-8
2
3
  {{ code_model.options['license_header'] }}
3
4
  {% macro iterate_models_py3() %}
4
5
  {% for schema in schemas %}
5
- from ._models_py3 import {{ schema }}
6
+ from .{{ code_model.get_models_filename(is_python3_file=True) }} import {{ schema }}
6
7
  {% endfor %}
7
8
  {% endmacro %}
8
9
 
@@ -14,19 +15,17 @@ try:
14
15
  {{ iterate_models_py3() | indent-}}
15
16
  except (SyntaxError, ImportError):
16
17
  {% for schema in schemas %}
17
- from ._models import {{ schema }} # type: ignore
18
+ from .{{ code_model.get_models_filename(is_python3_file=False) }} import {{ schema }} # type: ignore
18
19
  {% endfor %}
19
20
  {% endif %}
20
21
  {% endif %}
21
22
  {% if enums %}
22
23
 
23
- from ._{{ code_model.module_name }}_enums import (
24
- {% for enum in enums %}
25
- {{ enum }},
26
- {% endfor %}
27
- )
24
+ {% for enum in enums %}
25
+ from .{{ code_model.enums_filename }} import {{ enum }}
26
+ {% endfor %}
28
27
  {% endif %}
29
-
28
+ {{ keywords.patch_imports() }}
30
29
  __all__ = [
31
30
  {% for schema in schemas %}
32
31
  '{{ schema }}',
@@ -37,3 +36,5 @@ __all__ = [
37
36
  {% endfor %}
38
37
  {% endif %}
39
38
  ]
39
+ {{ keywords.extend_all }}
40
+ _patch_sdk()
@@ -1,29 +1,24 @@
1
1
  {% import 'keywords.jinja2' as keywords with context %}
2
2
  {% import 'operation_tools.jinja2' as op_tools %}
3
- {% set trace_decorator = "@distributed_trace_async" if async_mode else "@distributed_trace" %}
4
- {% set stream_request_parameter = "stream=" ~ ("True" if operation.is_stream_response else "False") %}
5
3
  {# actual template starts here #}
6
- {%- if code_model.options['tracing'] and operation.want_tracing -%}
7
- {{ trace_decorator }}
4
+ {% if operation.overloads and operation.public %}
5
+ {{ op_tools.generate_overloads(operation_serializer, operation) }}
8
6
  {% endif %}
9
7
  {{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
10
- {% if operation.want_description_docstring %}
8
+ {% if operation.public %}
11
9
  {{ op_tools.description(operation, operation_serializer) | indent }}{% endif %}
12
- cls = kwargs.pop('cls', None) {{ operation_serializer.cls_type_annotation(operation) }}
13
- {% if operation.deprecated %}
10
+ {% if not operation.abstract %}
11
+ {% if operation.deprecated %}
14
12
  warnings.warn('Method {{operation.name}} is deprecated', DeprecationWarning)
15
- {% endif %}
13
+ {% endif %}
16
14
  {{ op_tools.serialize(operation_serializer.error_map(operation)) | indent }}
17
- {% if operation.parameters.kwargs_to_pop(async_mode) %}
15
+ {% if operation_serializer.pop_kwargs_from_signature(operation) %}
18
16
  {{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
19
- {% endif %}
17
+ {% endif %}
20
18
  {{ op_tools.serialize(operation_serializer.call_request_builder(operation)) | indent }}
21
- pipeline_response = {{ keywords.await }}self._client._pipeline.run( # pylint: disable=protected-access
22
- request,
23
- {{ stream_request_parameter }},
24
- **kwargs
25
- )
19
+ {{ op_tools.serialize(operation_serializer.make_pipeline_call(operation)) | indent }}
26
20
  {{ op_tools.serialize(operation_serializer.handle_response(operation)) | indent }}
21
+ {% endif %}
27
22
  {% if not code_model.options["version_tolerant"] %}
28
23
  {{ operation_serializer.get_metadata_url(operation) }}
29
24
  {% endif %}
@@ -1,36 +1,37 @@
1
1
  {% set disable = " # pylint: disable=too-many-public-methods" if operation_group.operations | length > 20 else "" %}
2
- class {{ operation_group.class_name }}{{ object_base_class }}:{{ disable }}
3
- {% if not operation_group.is_empty_operation_group %}
2
+ {% set base_class = ("(" + operation_group.base_class(async_mode) + ")") if operation_group.base_class(async_mode) else "" %}
3
+ class {{ operation_group.class_name }}{{ base_class }}:{{ disable }}
4
+ {% if not operation_group.is_mixin %}
4
5
  """
5
6
  .. warning::
6
7
  **DO NOT** instantiate this class directly.
7
8
 
8
9
  Instead, you should access the following operations through
9
- :class:`{{ "~" + code_model.namespace + (".aio." if async_mode else ".") + code_model.class_name }}`'s
10
- :attr:`{{ operation_group.name }}` attribute.
10
+ :class:`{{ "~" + code_model.namespace + (".aio." if async_mode else ".") + code_model.client.name }}`'s
11
+ :attr:`{{ operation_group.property_name }}` attribute.
11
12
  """
12
13
 
13
- {% if code_model.schemas and code_model.options["models_mode"] %}
14
+ {% if code_model.public_model_types and code_model.options["models_mode"] %}
14
15
  models = _models
15
16
 
16
17
  {% endif %}
17
18
  def __init__(self, *args, **kwargs){{ return_none_type_annotation }}:
18
- args = list(args)
19
- self._client = args.pop(0) if args else kwargs.pop("client")
20
- self._config = args.pop(0) if args else kwargs.pop("config")
21
- self._serialize = args.pop(0) if args else kwargs.pop("serializer")
22
- self._deserialize = args.pop(0) if args else kwargs.pop("deserializer")
19
+ input_args = list(args)
20
+ self._client = input_args.pop(0) if input_args else kwargs.pop("client")
21
+ self._config = input_args.pop(0) if input_args else kwargs.pop("config")
22
+ self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer")
23
+ self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer")
23
24
 
24
25
  {% endif %}
25
26
  {% for operation in operation_group.operations %}
26
27
 
27
28
  {% set request_builder = operation.request_builder %}
28
29
  {% set operation_serializer = get_operation_serializer(operation) %}
29
- {% if is_lro(operation) and is_paging(operation) %}
30
+ {% if operation.operation_type == "lropaging" %}
30
31
  {%- macro someop() %}{% include "lro_paging_operation.py.jinja2" %}{% endmacro %}
31
- {% elif is_lro(operation) %}
32
+ {% elif operation.operation_type == "lro" %}
32
33
  {%- macro someop() %}{% include "lro_operation.py.jinja2" %}{% endmacro %}
33
- {% elif is_paging(operation) %}
34
+ {% elif operation.operation_type == "paging" %}
34
35
  {% macro someop() %}{% include "paging_operation.py.jinja2" %}{% endmacro %}
35
36
  {% else %}
36
37
  {% macro someop() %}{% include "operation.py.jinja2" %}{% endmacro %}
@@ -1,5 +1,4 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools %}
2
- {% set object_base_class = "" if async_mode else "(object)" %}
3
2
  {% set operations_description = "async operations" if async_mode else "operations" %}
4
3
  {% set return_none_type_annotation = " -> None" if async_mode else "" %}
5
4
  # pylint: disable=too-many-lines
@@ -13,7 +12,7 @@
13
12
  # fmt: off
14
13
  {% endif %}
15
14
  {% for operation_group in operation_groups %}
16
- {% for request_builder in code_model.rest.request_builders | selectattr("operation_group_name", "equalto", operation_group.name) %}
15
+ {% for request_builder in code_model.request_builders | selectattr("group_name", "equalto", operation_group.property_name) | rejectattr("is_overload") %}
17
16
 
18
17
  {% include "request_builder.py.jinja2" %}
19
18
  {% endfor %}