@typespec/http-client-python 0.15.2 → 0.16.1-dev.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/dist/emitter/code-model.d.ts.map +1 -1
- package/dist/emitter/code-model.js +8 -1
- package/dist/emitter/code-model.js.map +1 -1
- package/dist/emitter/emitter.d.ts.map +1 -1
- package/dist/emitter/emitter.js +5 -4
- package/dist/emitter/emitter.js.map +1 -1
- package/dist/emitter/http.d.ts +5 -0
- package/dist/emitter/http.d.ts.map +1 -1
- package/dist/emitter/http.js +20 -1
- package/dist/emitter/http.js.map +1 -1
- package/emitter/src/code-model.ts +12 -0
- package/emitter/src/emitter.ts +5 -4
- package/emitter/src/http.ts +23 -1
- package/emitter/temp/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/ci/regenerate.ts +5 -6
- package/eng/scripts/ci/util.py +1 -1
- package/eng/scripts/setup/__pycache__/package_manager.cpython-39.pyc +0 -0
- package/eng/scripts/setup/__pycache__/venvtools.cpython-39.pyc +0 -0
- package/eng/scripts/setup/install.py +21 -11
- package/eng/scripts/setup/install.ts +29 -4
- package/eng/scripts/setup/run-python3.ts +1 -1
- package/eng/scripts/setup/system-requirements.ts +13 -5
- package/generator/build/lib/pygen/__init__.py +7 -21
- package/generator/build/lib/pygen/black.py +2 -2
- package/generator/build/lib/pygen/codegen/__init__.py +4 -4
- package/generator/build/lib/pygen/codegen/models/__init__.py +2 -2
- package/generator/build/lib/pygen/codegen/models/base.py +9 -12
- package/generator/build/lib/pygen/codegen/models/base_builder.py +4 -6
- package/generator/build/lib/pygen/codegen/models/client.py +61 -102
- package/generator/build/lib/pygen/codegen/models/code_model.py +33 -29
- package/generator/build/lib/pygen/codegen/models/combined_type.py +7 -7
- package/generator/build/lib/pygen/codegen/models/constant_type.py +4 -11
- package/generator/build/lib/pygen/codegen/models/credential_types.py +9 -11
- package/generator/build/lib/pygen/codegen/models/dictionary_type.py +7 -8
- package/generator/build/lib/pygen/codegen/models/enum_type.py +7 -7
- package/generator/build/lib/pygen/codegen/models/imports.py +24 -29
- package/generator/build/lib/pygen/codegen/models/list_type.py +11 -14
- package/generator/build/lib/pygen/codegen/models/lro_operation.py +6 -6
- package/generator/build/lib/pygen/codegen/models/lro_paging_operation.py +2 -2
- package/generator/build/lib/pygen/codegen/models/model_type.py +11 -11
- package/generator/build/lib/pygen/codegen/models/operation.py +22 -56
- package/generator/build/lib/pygen/codegen/models/operation_group.py +11 -22
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +15 -19
- package/generator/build/lib/pygen/codegen/models/parameter.py +12 -21
- package/generator/build/lib/pygen/codegen/models/parameter_list.py +37 -39
- package/generator/build/lib/pygen/codegen/models/primitive_types.py +24 -18
- package/generator/build/lib/pygen/codegen/models/property.py +10 -10
- package/generator/build/lib/pygen/codegen/models/request_builder.py +7 -8
- package/generator/build/lib/pygen/codegen/models/request_builder_parameter.py +3 -3
- package/generator/build/lib/pygen/codegen/models/response.py +15 -40
- package/generator/build/lib/pygen/codegen/models/utils.py +2 -2
- package/generator/build/lib/pygen/codegen/serializers/__init__.py +15 -40
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +101 -94
- package/generator/build/lib/pygen/codegen/serializers/client_serializer.py +22 -25
- package/generator/build/lib/pygen/codegen/serializers/enum_serializer.py +2 -2
- package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +46 -60
- package/generator/build/lib/pygen/codegen/serializers/import_serializer.py +6 -7
- package/generator/build/lib/pygen/codegen/serializers/model_init_serializer.py +1 -2
- package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +36 -29
- package/generator/build/lib/pygen/codegen/serializers/operation_groups_serializer.py +8 -3
- package/generator/build/lib/pygen/codegen/serializers/operations_init_serializer.py +5 -6
- package/generator/build/lib/pygen/codegen/serializers/parameter_serializer.py +28 -18
- package/generator/build/lib/pygen/codegen/serializers/patch_serializer.py +1 -2
- package/generator/build/lib/pygen/codegen/serializers/request_builders_serializer.py +1 -2
- package/generator/build/lib/pygen/codegen/serializers/sample_serializer.py +9 -14
- package/generator/build/lib/pygen/codegen/serializers/test_serializer.py +7 -7
- package/generator/build/lib/pygen/codegen/serializers/utils.py +2 -2
- package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +30 -24
- package/generator/build/lib/pygen/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/operation_group.py.jinja2 +1 -11
- package/generator/build/lib/pygen/codegen/templates/operations_folder_init.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 +8 -1
- package/generator/build/lib/pygen/codegen/templates/patch.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +11 -13
- package/generator/build/lib/pygen/codegen/templates/utils.py.jinja2 +6 -6
- package/generator/build/lib/pygen/preprocess/__init__.py +47 -30
- package/generator/build/lib/pygen/preprocess/helpers.py +2 -2
- package/generator/build/lib/pygen/utils.py +6 -6
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/__init__.py +7 -21
- package/generator/pygen/black.py +2 -2
- package/generator/pygen/codegen/__init__.py +4 -4
- package/generator/pygen/codegen/models/__init__.py +2 -2
- package/generator/pygen/codegen/models/base.py +9 -12
- package/generator/pygen/codegen/models/base_builder.py +4 -6
- package/generator/pygen/codegen/models/client.py +61 -102
- package/generator/pygen/codegen/models/code_model.py +33 -29
- package/generator/pygen/codegen/models/combined_type.py +7 -7
- package/generator/pygen/codegen/models/constant_type.py +4 -11
- package/generator/pygen/codegen/models/credential_types.py +9 -11
- package/generator/pygen/codegen/models/dictionary_type.py +7 -8
- package/generator/pygen/codegen/models/enum_type.py +7 -7
- package/generator/pygen/codegen/models/imports.py +24 -29
- package/generator/pygen/codegen/models/list_type.py +11 -14
- package/generator/pygen/codegen/models/lro_operation.py +6 -6
- package/generator/pygen/codegen/models/lro_paging_operation.py +2 -2
- package/generator/pygen/codegen/models/model_type.py +11 -11
- package/generator/pygen/codegen/models/operation.py +22 -56
- package/generator/pygen/codegen/models/operation_group.py +11 -22
- package/generator/pygen/codegen/models/paging_operation.py +15 -19
- package/generator/pygen/codegen/models/parameter.py +12 -21
- package/generator/pygen/codegen/models/parameter_list.py +37 -39
- package/generator/pygen/codegen/models/primitive_types.py +24 -18
- package/generator/pygen/codegen/models/property.py +10 -10
- package/generator/pygen/codegen/models/request_builder.py +7 -8
- package/generator/pygen/codegen/models/request_builder_parameter.py +3 -3
- package/generator/pygen/codegen/models/response.py +15 -40
- package/generator/pygen/codegen/models/utils.py +2 -2
- package/generator/pygen/codegen/serializers/__init__.py +15 -40
- package/generator/pygen/codegen/serializers/builder_serializer.py +101 -94
- package/generator/pygen/codegen/serializers/client_serializer.py +22 -25
- package/generator/pygen/codegen/serializers/enum_serializer.py +2 -2
- package/generator/pygen/codegen/serializers/general_serializer.py +46 -60
- package/generator/pygen/codegen/serializers/import_serializer.py +6 -7
- package/generator/pygen/codegen/serializers/model_init_serializer.py +1 -2
- package/generator/pygen/codegen/serializers/model_serializer.py +36 -29
- package/generator/pygen/codegen/serializers/operation_groups_serializer.py +8 -3
- package/generator/pygen/codegen/serializers/operations_init_serializer.py +5 -6
- package/generator/pygen/codegen/serializers/parameter_serializer.py +28 -18
- package/generator/pygen/codegen/serializers/patch_serializer.py +1 -2
- package/generator/pygen/codegen/serializers/request_builders_serializer.py +1 -2
- package/generator/pygen/codegen/serializers/sample_serializer.py +9 -14
- package/generator/pygen/codegen/serializers/test_serializer.py +7 -7
- package/generator/pygen/codegen/serializers/utils.py +2 -2
- package/generator/pygen/codegen/templates/model_base.py.jinja2 +30 -24
- package/generator/pygen/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/operation_group.py.jinja2 +1 -11
- package/generator/pygen/codegen/templates/operations_folder_init.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +1 -1
- package/generator/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 +8 -1
- package/generator/pygen/codegen/templates/patch.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/serialization.py.jinja2 +11 -13
- package/generator/pygen/codegen/templates/utils.py.jinja2 +6 -6
- package/generator/pygen/preprocess/__init__.py +47 -30
- package/generator/pygen/preprocess/helpers.py +2 -2
- package/generator/pygen/utils.py +6 -6
- package/generator/pygen.egg-info/SOURCES.txt +0 -2
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_operationtemplates_async.py +79 -0
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_hierrarchy_building_async.py +53 -0
- package/generator/test/azure/mock_api_tests/asynctests/test_client_naming_async.py +4 -4
- package/generator/test/azure/mock_api_tests/asynctests/test_client_naming_enum_conflict_async.py +37 -0
- package/generator/test/azure/mock_api_tests/conftest.py +2 -2
- package/generator/test/azure/mock_api_tests/test_azure_arm_operationtemplates.py +72 -0
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_hierrarchy_building.py +45 -0
- package/generator/test/azure/mock_api_tests/test_client_naming.py +3 -3
- package/generator/test/azure/mock_api_tests/test_client_naming_enum_conflict.py +35 -0
- package/generator/test/azure/requirements.txt +2 -0
- package/generator/test/unbranded/mock_api_tests/conftest.py +1 -2
- package/generator/test/unittests/test_model_base_serialization.py +135 -92
- package/generator/test/unittests/test_model_base_xml_serialization.py +19 -23
- package/package.json +8 -8
- package/generator/build/lib/pygen/codegen/serializers/metadata_serializer.py +0 -216
- package/generator/build/lib/pygen/codegen/templates/metadata.json.jinja2 +0 -167
- package/generator/pygen/codegen/serializers/metadata_serializer.py +0 -216
- package/generator/pygen/codegen/templates/metadata.json.jinja2 +0 -167
|
@@ -4,11 +4,7 @@
|
|
|
4
4
|
# ------------------------------------
|
|
5
5
|
import xml.etree.ElementTree as ET
|
|
6
6
|
|
|
7
|
-
from typing import
|
|
8
|
-
List,
|
|
9
|
-
Literal,
|
|
10
|
-
Dict,
|
|
11
|
-
)
|
|
7
|
+
from typing import Literal
|
|
12
8
|
|
|
13
9
|
from specialwords._utils.model_base import (
|
|
14
10
|
_get_element,
|
|
@@ -124,7 +120,7 @@ class TestXmlDeserialization:
|
|
|
124
120
|
</Data>"""
|
|
125
121
|
|
|
126
122
|
class XmlModel(Model):
|
|
127
|
-
metadata:
|
|
123
|
+
metadata: dict[str, str] = rest_field(name="Metadata", xml={"name": "Metadata"})
|
|
128
124
|
|
|
129
125
|
def __init__(self, *args, **kwargs):
|
|
130
126
|
super().__init__(*args, **kwargs)
|
|
@@ -145,7 +141,7 @@ class TestXmlDeserialization:
|
|
|
145
141
|
</Data>"""
|
|
146
142
|
|
|
147
143
|
class XmlModel(Model):
|
|
148
|
-
age:
|
|
144
|
+
age: list[str] = rest_field(name="age", xml={"name": "Age"})
|
|
149
145
|
|
|
150
146
|
def __init__(self, *args, **kwargs):
|
|
151
147
|
super().__init__(*args, **kwargs)
|
|
@@ -161,7 +157,7 @@ class TestXmlDeserialization:
|
|
|
161
157
|
<Data/>"""
|
|
162
158
|
|
|
163
159
|
class XmlModel(Model):
|
|
164
|
-
age:
|
|
160
|
+
age: list[str] = rest_field(name="age", xml={"name": "Age", "unwrapped": True})
|
|
165
161
|
|
|
166
162
|
def __init__(self, *args, **kwargs):
|
|
167
163
|
super().__init__(*args, **kwargs)
|
|
@@ -183,7 +179,7 @@ class TestXmlDeserialization:
|
|
|
183
179
|
</AppleBarrel>"""
|
|
184
180
|
|
|
185
181
|
class AppleBarrel(Model):
|
|
186
|
-
good_apples:
|
|
182
|
+
good_apples: list[str] = rest_field(name="GoodApples", xml={"name": "GoodApples", "itemsName": "Apple"})
|
|
187
183
|
|
|
188
184
|
def __init__(self, *args, **kwargs):
|
|
189
185
|
super().__init__(*args, **kwargs)
|
|
@@ -203,7 +199,7 @@ class TestXmlDeserialization:
|
|
|
203
199
|
</AppleBarrel>"""
|
|
204
200
|
|
|
205
201
|
class AppleBarrel(Model):
|
|
206
|
-
good_apples:
|
|
202
|
+
good_apples: list[str] = rest_field(
|
|
207
203
|
name="GoodApples",
|
|
208
204
|
xml={"name": "GoodApples", "unwrapped": True, "itemsName": "Apple"},
|
|
209
205
|
)
|
|
@@ -236,7 +232,7 @@ class TestXmlDeserialization:
|
|
|
236
232
|
_xml = {"name": "Apple"}
|
|
237
233
|
|
|
238
234
|
class AppleBarrel(Model):
|
|
239
|
-
good_apples:
|
|
235
|
+
good_apples: list[Apple] = rest_field(name="GoodApples", xml={"name": "GoodApples", "itemsName": "Apple"})
|
|
240
236
|
|
|
241
237
|
def __init__(self, *args, **kwargs):
|
|
242
238
|
super().__init__(*args, **kwargs)
|
|
@@ -264,7 +260,7 @@ class TestXmlDeserialization:
|
|
|
264
260
|
_xml = {"name": "Apple"}
|
|
265
261
|
|
|
266
262
|
class AppleBarrel(Model):
|
|
267
|
-
good_apples:
|
|
263
|
+
good_apples: list[Apple] = rest_field(
|
|
268
264
|
name="GoodApples",
|
|
269
265
|
xml={"name": "GoodApples", "unwrapped": True, "itemsName": "Apple"},
|
|
270
266
|
)
|
|
@@ -295,7 +291,7 @@ class TestXmlDeserialization:
|
|
|
295
291
|
_xml = {"name": "Apple"}
|
|
296
292
|
|
|
297
293
|
class AppleBarrel(Model):
|
|
298
|
-
good_apples:
|
|
294
|
+
good_apples: list[Apple] = rest_field(
|
|
299
295
|
name="GoodApples",
|
|
300
296
|
xml={"name": "GoodApples", "unwrapped": True, "itemsName": "Apple"},
|
|
301
297
|
)
|
|
@@ -427,7 +423,7 @@ class TestXmlDeserialization:
|
|
|
427
423
|
|
|
428
424
|
class XmlRoot(Model):
|
|
429
425
|
author: QueueDescriptionResponseAuthor = rest_field(name="author")
|
|
430
|
-
authorization_rules:
|
|
426
|
+
authorization_rules: list[AuthorizationRule] = rest_field(
|
|
431
427
|
name="AuthorizationRules",
|
|
432
428
|
xml={
|
|
433
429
|
"ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
|
|
@@ -461,7 +457,7 @@ class TestXmlDeserialization:
|
|
|
461
457
|
</entry>"""
|
|
462
458
|
|
|
463
459
|
class RuleFilter(Model):
|
|
464
|
-
__mapping__:
|
|
460
|
+
__mapping__: dict[str, Model] = {}
|
|
465
461
|
type: Literal[None] = rest_discriminator(
|
|
466
462
|
name="type",
|
|
467
463
|
xml={
|
|
@@ -641,7 +637,7 @@ class TestXmlSerialization:
|
|
|
641
637
|
)
|
|
642
638
|
|
|
643
639
|
class XmlModel(Model):
|
|
644
|
-
metadata:
|
|
640
|
+
metadata: dict[str, str] = rest_field(name="Metadata", xml={"name": "Metadata"})
|
|
645
641
|
|
|
646
642
|
def __init__(self, *args, **kwargs):
|
|
647
643
|
super().__init__(*args, **kwargs)
|
|
@@ -707,7 +703,7 @@ class TestXmlSerialization:
|
|
|
707
703
|
)
|
|
708
704
|
|
|
709
705
|
class AppleBarrel(Model):
|
|
710
|
-
good_apples:
|
|
706
|
+
good_apples: list[str] = rest_field(name="GoodApples", xml={"name": "GoodApples"})
|
|
711
707
|
|
|
712
708
|
def __init__(self, *args, **kwargs):
|
|
713
709
|
super().__init__(*args, **kwargs)
|
|
@@ -729,7 +725,7 @@ class TestXmlSerialization:
|
|
|
729
725
|
)
|
|
730
726
|
|
|
731
727
|
class AppleBarrel(Model):
|
|
732
|
-
good_apples:
|
|
728
|
+
good_apples: list[str] = rest_field(name="GoodApples", xml={"name": "GoodApples", "unwrapped": True})
|
|
733
729
|
|
|
734
730
|
def __init__(self, *args, **kwargs):
|
|
735
731
|
super().__init__(*args, **kwargs)
|
|
@@ -753,7 +749,7 @@ class TestXmlSerialization:
|
|
|
753
749
|
)
|
|
754
750
|
|
|
755
751
|
class AppleBarrel(Model):
|
|
756
|
-
good_apples:
|
|
752
|
+
good_apples: list[str] = rest_field(name="GoodApples", xml={"name": "GoodApples", "itemsName": "string"})
|
|
757
753
|
|
|
758
754
|
def __init__(self, *args, **kwargs):
|
|
759
755
|
super().__init__(*args, **kwargs)
|
|
@@ -775,7 +771,7 @@ class TestXmlSerialization:
|
|
|
775
771
|
)
|
|
776
772
|
|
|
777
773
|
class AppleBarrel(Model):
|
|
778
|
-
good_apples:
|
|
774
|
+
good_apples: list[str] = rest_field(
|
|
779
775
|
name="GoodApples",
|
|
780
776
|
xml={"name": "GoodApples", "unwrapped": True, "itemsName": "string"},
|
|
781
777
|
)
|
|
@@ -810,7 +806,7 @@ class TestXmlSerialization:
|
|
|
810
806
|
_xml = {"name": "Apple"}
|
|
811
807
|
|
|
812
808
|
class AppleBarrel(Model):
|
|
813
|
-
good_apples:
|
|
809
|
+
good_apples: list[Apple] = rest_field(name="GoodApples", xml={"name": "GoodApples"})
|
|
814
810
|
|
|
815
811
|
def __init__(self, *args, **kwargs):
|
|
816
812
|
super().__init__(*args, **kwargs)
|
|
@@ -841,7 +837,7 @@ class TestXmlSerialization:
|
|
|
841
837
|
_xml = {"name": "Apple"}
|
|
842
838
|
|
|
843
839
|
class AppleBarrel(Model):
|
|
844
|
-
good_apples:
|
|
840
|
+
good_apples: list[Apple] = rest_field(name="GoodApples", xml={"name": "GoodApples", "unwrapped": True})
|
|
845
841
|
|
|
846
842
|
def __init__(self, *args, **kwargs):
|
|
847
843
|
super().__init__(*args, **kwargs)
|
|
@@ -975,7 +971,7 @@ class TestXmlSerialization:
|
|
|
975
971
|
|
|
976
972
|
class XmlRoot(Model):
|
|
977
973
|
author: QueueDescriptionResponseAuthor = rest_field(name="author")
|
|
978
|
-
authorization_rules:
|
|
974
|
+
authorization_rules: list[AuthorizationRule] = rest_field(
|
|
979
975
|
name="AuthorizationRules",
|
|
980
976
|
xml={
|
|
981
977
|
"ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/http-client-python",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1-dev.0",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "TypeSpec emitter for Python SDKs",
|
|
6
6
|
"homepage": "https://typespec.io",
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
"emitter"
|
|
55
55
|
],
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@azure-tools/typespec-autorest": ">=0.59.
|
|
57
|
+
"@azure-tools/typespec-autorest": ">=0.59.1 <1.0.0",
|
|
58
58
|
"@azure-tools/typespec-azure-core": ">=0.59.0 <1.0.0",
|
|
59
|
-
"@azure-tools/typespec-azure-resource-manager": ">=0.59.
|
|
59
|
+
"@azure-tools/typespec-azure-resource-manager": ">=0.59.2 <1.0.0",
|
|
60
60
|
"@azure-tools/typespec-azure-rulesets": ">=0.59.0 <1.0.0",
|
|
61
|
-
"@azure-tools/typespec-client-generator-core": ">=0.59.
|
|
61
|
+
"@azure-tools/typespec-client-generator-core": ">=0.59.1 <1.0.0",
|
|
62
62
|
"@typespec/compiler": "^1.3.0",
|
|
63
63
|
"@typespec/http": "^1.3.0",
|
|
64
64
|
"@typespec/openapi": "^1.3.0",
|
|
@@ -77,12 +77,12 @@
|
|
|
77
77
|
"tsx": "~4.19.1"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@azure-tools/typespec-autorest": "~0.59.
|
|
80
|
+
"@azure-tools/typespec-autorest": "~0.59.1",
|
|
81
81
|
"@azure-tools/typespec-azure-core": "~0.59.0",
|
|
82
|
-
"@azure-tools/typespec-azure-resource-manager": "~0.59.
|
|
82
|
+
"@azure-tools/typespec-azure-resource-manager": "~0.59.2",
|
|
83
83
|
"@azure-tools/typespec-azure-rulesets": "~0.59.0",
|
|
84
|
-
"@azure-tools/typespec-client-generator-core": "~0.59.
|
|
85
|
-
"@azure-tools/azure-http-specs": "0.1.0-alpha.
|
|
84
|
+
"@azure-tools/typespec-client-generator-core": "~0.59.1",
|
|
85
|
+
"@azure-tools/azure-http-specs": "0.1.0-alpha.27",
|
|
86
86
|
"@typespec/compiler": "^1.3.0",
|
|
87
87
|
"@typespec/http": "^1.3.0",
|
|
88
88
|
"@typespec/openapi": "^1.3.0",
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
# -------------------------------------------------------------------------
|
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
-
# license information.
|
|
5
|
-
# --------------------------------------------------------------------------
|
|
6
|
-
import functools
|
|
7
|
-
import json
|
|
8
|
-
from typing import List, Optional, Set, Tuple, Dict, Union, Any
|
|
9
|
-
from jinja2 import Environment
|
|
10
|
-
from ..models import (
|
|
11
|
-
OperationGroup,
|
|
12
|
-
LROOperation,
|
|
13
|
-
PagingOperation,
|
|
14
|
-
TypingSection,
|
|
15
|
-
ImportType,
|
|
16
|
-
CodeModel,
|
|
17
|
-
)
|
|
18
|
-
from .builder_serializer import get_operation_serializer
|
|
19
|
-
from .base_serializer import BaseSerializer
|
|
20
|
-
from .import_serializer import FileImportSerializer
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def _to_string(data: Union[Tuple[Any], List[Any], str]) -> str:
|
|
24
|
-
if isinstance(data, (list, tuple)):
|
|
25
|
-
return "".join([_to_string(item) for item in data])
|
|
26
|
-
return str(data)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def _json_serialize_imports(
|
|
30
|
-
imports: Dict[
|
|
31
|
-
TypingSection,
|
|
32
|
-
Dict[
|
|
33
|
-
ImportType,
|
|
34
|
-
Dict[
|
|
35
|
-
str,
|
|
36
|
-
Set[
|
|
37
|
-
Optional[
|
|
38
|
-
Union[
|
|
39
|
-
str,
|
|
40
|
-
Tuple[str, str],
|
|
41
|
-
Tuple[
|
|
42
|
-
str,
|
|
43
|
-
Optional[str],
|
|
44
|
-
Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
|
|
45
|
-
],
|
|
46
|
-
]
|
|
47
|
-
]
|
|
48
|
-
],
|
|
49
|
-
],
|
|
50
|
-
],
|
|
51
|
-
],
|
|
52
|
-
) -> str:
|
|
53
|
-
if not imports:
|
|
54
|
-
return ""
|
|
55
|
-
|
|
56
|
-
json_serialize_imports = {}
|
|
57
|
-
# need to make name_import set -> list to make the dictionary json serializable
|
|
58
|
-
# not using an OrderedDict since we're iterating through a set and the order there varies
|
|
59
|
-
# going to sort the list instead
|
|
60
|
-
|
|
61
|
-
for typing_section_key, typing_section_value in imports.items():
|
|
62
|
-
json_import_type_dictionary = {}
|
|
63
|
-
for import_type_key, import_type_value in typing_section_value.items():
|
|
64
|
-
json_package_name_dictionary = {}
|
|
65
|
-
for package_name, name_imports in import_type_value.items():
|
|
66
|
-
name_import_ordered_list = []
|
|
67
|
-
if name_imports:
|
|
68
|
-
name_import_ordered_list = list(name_imports)
|
|
69
|
-
name_import_ordered_list.sort(
|
|
70
|
-
key=lambda e: (
|
|
71
|
-
_to_string(e) # type: ignore
|
|
72
|
-
if isinstance(e, (list, tuple))
|
|
73
|
-
else e if isinstance(e, str) else ""
|
|
74
|
-
)
|
|
75
|
-
)
|
|
76
|
-
json_package_name_dictionary[package_name] = name_import_ordered_list
|
|
77
|
-
json_import_type_dictionary[import_type_key] = json_package_name_dictionary
|
|
78
|
-
json_serialize_imports[typing_section_key] = json_import_type_dictionary
|
|
79
|
-
return json.dumps(json_serialize_imports)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def _mixin_imports(
|
|
83
|
-
mixin_operation_group: Optional[OperationGroup],
|
|
84
|
-
) -> Tuple[Optional[str], Optional[str]]:
|
|
85
|
-
if not mixin_operation_group:
|
|
86
|
-
return None, None
|
|
87
|
-
|
|
88
|
-
sync_mixin_imports = mixin_operation_group.imports_for_multiapi(async_mode=False)
|
|
89
|
-
async_mixin_imports = mixin_operation_group.imports_for_multiapi(async_mode=True)
|
|
90
|
-
|
|
91
|
-
return _json_serialize_imports(sync_mixin_imports.to_dict()), _json_serialize_imports(async_mixin_imports.to_dict())
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def _mixin_typing_definitions(
|
|
95
|
-
mixin_operation_group: Optional[OperationGroup],
|
|
96
|
-
) -> Tuple[Optional[str], Optional[str]]:
|
|
97
|
-
if not mixin_operation_group:
|
|
98
|
-
return None, None
|
|
99
|
-
|
|
100
|
-
sync_mixin_imports = mixin_operation_group.imports_for_multiapi(async_mode=False)
|
|
101
|
-
async_mixin_imports = mixin_operation_group.imports_for_multiapi(async_mode=True)
|
|
102
|
-
sync_mixin_typing_definitions = FileImportSerializer(sync_mixin_imports, False).get_typing_definitions()
|
|
103
|
-
async_mixin_typing_definitions = FileImportSerializer(async_mixin_imports, True).get_typing_definitions()
|
|
104
|
-
|
|
105
|
-
return sync_mixin_typing_definitions, async_mixin_typing_definitions
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
class MetadataSerializer(BaseSerializer):
|
|
109
|
-
def __init__(self, code_model: CodeModel, env: Environment, *, client_namespace: Optional[str] = None):
|
|
110
|
-
super().__init__(code_model, env, client_namespace=client_namespace)
|
|
111
|
-
self.client = self.code_model.clients[0] # we only do one client for multiapi
|
|
112
|
-
|
|
113
|
-
def _choose_api_version(self) -> Tuple[str, List[str]]:
|
|
114
|
-
chosen_version = ""
|
|
115
|
-
total_api_version_set: Set[str] = set()
|
|
116
|
-
for client in self.code_model.clients:
|
|
117
|
-
for operation_group in client.operation_groups:
|
|
118
|
-
total_api_version_set.update(operation_group.api_versions)
|
|
119
|
-
|
|
120
|
-
total_api_version_list = list(total_api_version_set)
|
|
121
|
-
total_api_version_list.sort()
|
|
122
|
-
|
|
123
|
-
# switching ' to " so json can decode the dict we end up writing to file
|
|
124
|
-
total_api_version_list = [str(api_version).replace("'", '"') for api_version in total_api_version_list]
|
|
125
|
-
if len(total_api_version_list) == 1:
|
|
126
|
-
chosen_version = total_api_version_list[0]
|
|
127
|
-
elif len(total_api_version_list) > 1:
|
|
128
|
-
module_version = self.code_model.namespace.split(".")[-1]
|
|
129
|
-
for api_version in total_api_version_list:
|
|
130
|
-
if "v{}".format(api_version.replace("-", "_")) == module_version:
|
|
131
|
-
chosen_version = api_version
|
|
132
|
-
|
|
133
|
-
return chosen_version, total_api_version_list
|
|
134
|
-
|
|
135
|
-
def serialize(self) -> str:
|
|
136
|
-
def _is_lro(operation):
|
|
137
|
-
return isinstance(operation, LROOperation)
|
|
138
|
-
|
|
139
|
-
def _is_paging(operation):
|
|
140
|
-
return isinstance(operation, PagingOperation)
|
|
141
|
-
|
|
142
|
-
mixin_operation_group: Optional[OperationGroup] = next(
|
|
143
|
-
(
|
|
144
|
-
operation_group
|
|
145
|
-
for client in self.code_model.clients
|
|
146
|
-
for operation_group in client.operation_groups
|
|
147
|
-
if operation_group.is_mixin
|
|
148
|
-
),
|
|
149
|
-
None,
|
|
150
|
-
)
|
|
151
|
-
mixin_operations = mixin_operation_group.operations if mixin_operation_group else []
|
|
152
|
-
sync_mixin_imports, async_mixin_imports = _mixin_imports(mixin_operation_group)
|
|
153
|
-
(
|
|
154
|
-
sync_mixin_typing_definitions,
|
|
155
|
-
async_mixin_typing_definitions,
|
|
156
|
-
) = _mixin_typing_definitions(mixin_operation_group)
|
|
157
|
-
|
|
158
|
-
chosen_version, total_api_version_list = self._choose_api_version()
|
|
159
|
-
|
|
160
|
-
# setting to true, because for multiapi we always generate with a version file with version 0.1.0
|
|
161
|
-
self.code_model.options["package-version"] = "0.1.0"
|
|
162
|
-
template = self.env.get_template("metadata.json.jinja2")
|
|
163
|
-
|
|
164
|
-
client_serialize_namespace = self.code_model.get_serialize_namespace(self.client_namespace, async_mode=False)
|
|
165
|
-
client_serialize_namespace_async = self.code_model.get_serialize_namespace(
|
|
166
|
-
self.client_namespace, async_mode=True
|
|
167
|
-
)
|
|
168
|
-
return template.render(
|
|
169
|
-
code_model=self.code_model,
|
|
170
|
-
chosen_version=chosen_version,
|
|
171
|
-
total_api_version_list=total_api_version_list,
|
|
172
|
-
client=self.client,
|
|
173
|
-
global_parameters=self.client.parameters,
|
|
174
|
-
mixin_operations=mixin_operations,
|
|
175
|
-
any=any,
|
|
176
|
-
is_lro=_is_lro,
|
|
177
|
-
is_paging=_is_paging,
|
|
178
|
-
str=str,
|
|
179
|
-
sync_mixin_imports=sync_mixin_imports,
|
|
180
|
-
async_mixin_imports=async_mixin_imports,
|
|
181
|
-
sync_mixin_typing_definitions=sync_mixin_typing_definitions,
|
|
182
|
-
async_mixin_typing_definitions=async_mixin_typing_definitions,
|
|
183
|
-
sync_client_imports=_json_serialize_imports(
|
|
184
|
-
self.client.imports_for_multiapi(
|
|
185
|
-
async_mode=False, serialize_namespace=client_serialize_namespace
|
|
186
|
-
).to_dict()
|
|
187
|
-
),
|
|
188
|
-
async_client_imports=_json_serialize_imports(
|
|
189
|
-
self.client.imports_for_multiapi(
|
|
190
|
-
async_mode=True, serialize_namespace=client_serialize_namespace_async
|
|
191
|
-
).to_dict()
|
|
192
|
-
),
|
|
193
|
-
sync_config_imports=_json_serialize_imports(
|
|
194
|
-
self.client.config.imports_for_multiapi(
|
|
195
|
-
async_mode=False, serialize_namespace=client_serialize_namespace
|
|
196
|
-
).to_dict()
|
|
197
|
-
),
|
|
198
|
-
async_config_imports=_json_serialize_imports(
|
|
199
|
-
self.client.config.imports_for_multiapi(
|
|
200
|
-
async_mode=True, serialize_namespace=client_serialize_namespace_async
|
|
201
|
-
).to_dict()
|
|
202
|
-
),
|
|
203
|
-
get_async_operation_serializer=functools.partial(
|
|
204
|
-
get_operation_serializer,
|
|
205
|
-
code_model=self.client.code_model,
|
|
206
|
-
async_mode=True,
|
|
207
|
-
client_namespace=self.client_namespace,
|
|
208
|
-
),
|
|
209
|
-
get_sync_operation_serializer=functools.partial(
|
|
210
|
-
get_operation_serializer,
|
|
211
|
-
code_model=self.client.code_model,
|
|
212
|
-
async_mode=False,
|
|
213
|
-
client_namespace=self.client_namespace,
|
|
214
|
-
),
|
|
215
|
-
has_credential=bool(self.client.credential),
|
|
216
|
-
)
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
{% import 'operation_tools.jinja2' as op_tools %}
|
|
2
|
-
{% import 'keywords.jinja2' as keywords %}
|
|
3
|
-
{
|
|
4
|
-
"chosen_version": {{ chosen_version | tojson }},
|
|
5
|
-
"total_api_version_list": {{ total_api_version_list | tojson }},
|
|
6
|
-
"client": {
|
|
7
|
-
"name": {{ client.name | tojson }},
|
|
8
|
-
"filename": {{ ("_" + client.legacy_filename) | tojson }},
|
|
9
|
-
"description": {{ client.description | tojson }},
|
|
10
|
-
"host_value": {{ (client.parameters.host.client_default_value_declaration if not client.has_parameterized_host else None) | tojson }},
|
|
11
|
-
"parameterized_host_template": {{ (keywords.escape_str(client.url) if client.has_parameterized_host else None) | tojson }},
|
|
12
|
-
"azure_arm": {{ client.code_model.options["azure-arm"] | tojson }},
|
|
13
|
-
"has_public_lro_operations": {{ client.has_public_lro_operations | tojson }},
|
|
14
|
-
"client-side-validation": {{ client.code_model.options["client-side-validation"] | tojson }},
|
|
15
|
-
"sync_imports": {{ sync_client_imports | tojson }},
|
|
16
|
-
"async_imports": {{ async_client_imports | tojson }}
|
|
17
|
-
},
|
|
18
|
-
"global_parameters": {
|
|
19
|
-
"sync": {
|
|
20
|
-
{% for gp in global_parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") %}
|
|
21
|
-
{{ gp.client_name | tojson }}: {
|
|
22
|
-
"signature": {{ gp.method_signature(async_mode=False) | tojson }},
|
|
23
|
-
"description": {{ gp.description | tojson }},
|
|
24
|
-
"docstring_type": {{ gp.docstring_type(async_mode=False) | tojson }},
|
|
25
|
-
"required": {{ (not gp.optional) | tojson }},
|
|
26
|
-
"method_location": {{ gp.method_location | tojson }}
|
|
27
|
-
}{{ "," if not loop.last else "" }}
|
|
28
|
-
{% endfor %}
|
|
29
|
-
},
|
|
30
|
-
"async": {
|
|
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(async_mode=True)) | tojson }},
|
|
34
|
-
"description": {{ gp.description | tojson }},
|
|
35
|
-
"docstring_type": {{ gp.docstring_type(async_mode=True) | tojson }},
|
|
36
|
-
"required": {{ (not gp.optional) | tojson }}
|
|
37
|
-
}{{ "," if not loop.last else "" }}
|
|
38
|
-
{% endfor %}
|
|
39
|
-
},
|
|
40
|
-
"constant": {
|
|
41
|
-
{% for gp in client.parameters.constant | rejectattr("client_name", "equalto", "api_version") %}
|
|
42
|
-
{{ gp.client_name | tojson }}: {{ gp.constant_declaration | tojson }}{{ "," if not loop.last else "" }}
|
|
43
|
-
{% endfor %}
|
|
44
|
-
},
|
|
45
|
-
"call": {{ client.parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") | map(attribute="client_name") | join(', ') | tojson }},
|
|
46
|
-
"service_client_specific": {
|
|
47
|
-
"sync": {
|
|
48
|
-
"api_version": {
|
|
49
|
-
"signature": "api_version: Optional[str]=None,",
|
|
50
|
-
"description": "API version to use if no profile is provided, or if missing in profile.",
|
|
51
|
-
"docstring_type": "str",
|
|
52
|
-
"required": false,
|
|
53
|
-
"method_location": "positional"
|
|
54
|
-
},
|
|
55
|
-
{% if not client.has_parameterized_host %}
|
|
56
|
-
"base_url": {
|
|
57
|
-
"signature": {{ client.parameters.host.method_signature(async_mode=False) | tojson }},
|
|
58
|
-
"description": "Service URL",
|
|
59
|
-
"docstring_type": "str",
|
|
60
|
-
"required": false,
|
|
61
|
-
"method_location": "positional"
|
|
62
|
-
},
|
|
63
|
-
{% endif %}
|
|
64
|
-
"profile": {
|
|
65
|
-
"signature": "profile: KnownProfiles=KnownProfiles.default,",
|
|
66
|
-
"description": "A profile definition, from KnownProfiles to dict.",
|
|
67
|
-
"docstring_type": "azure.profiles.KnownProfiles",
|
|
68
|
-
"required": false,
|
|
69
|
-
"method_location": "positional"
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
"async": {
|
|
73
|
-
"api_version": {
|
|
74
|
-
"signature": "api_version: Optional[str] = None,",
|
|
75
|
-
"description": "API version to use if no profile is provided, or if missing in profile.",
|
|
76
|
-
"docstring_type": "str",
|
|
77
|
-
"required": false,
|
|
78
|
-
"method_location": "positional"
|
|
79
|
-
},
|
|
80
|
-
{% if not client.has_parameterized_host %}
|
|
81
|
-
"base_url": {
|
|
82
|
-
"signature": {{ client.parameters.host.method_signature(async_mode=True) | tojson }},
|
|
83
|
-
"description": "Service URL",
|
|
84
|
-
"docstring_type": "str",
|
|
85
|
-
"required": false,
|
|
86
|
-
"method_location": "positional"
|
|
87
|
-
},
|
|
88
|
-
{% endif %}
|
|
89
|
-
"profile": {
|
|
90
|
-
"signature": "profile: KnownProfiles = KnownProfiles.default,",
|
|
91
|
-
"description": "A profile definition, from KnownProfiles to dict.",
|
|
92
|
-
"docstring_type": "azure.profiles.KnownProfiles",
|
|
93
|
-
"required": false,
|
|
94
|
-
"method_location": "positional"
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
"config": {
|
|
100
|
-
"credential": {{ has_credential | tojson }},
|
|
101
|
-
"credential_scopes": {{ (client.credential.type.policy.credential_scopes if has_credential and client.credential.type.policy.credential_scopes is defined else None)| tojson}},
|
|
102
|
-
"credential_call_sync": {{ (client.credential.type.policy.call(async_mode=False) if has_credential else None) | tojson }},
|
|
103
|
-
"credential_call_async": {{ (client.credential.type.policy.call(async_mode=True) if has_credential else None) | tojson }},
|
|
104
|
-
"sync_imports": {{ sync_config_imports | tojson }},
|
|
105
|
-
"async_imports": {{ async_config_imports | tojson }}
|
|
106
|
-
},
|
|
107
|
-
"operation_groups": {
|
|
108
|
-
{% for operation_group in client.operation_groups | rejectattr('is_mixin') %}
|
|
109
|
-
{{ operation_group.property_name | tojson }}: {{ operation_group.class_name | tojson }}{{ "," if not loop.last else "" }}
|
|
110
|
-
{% endfor %}
|
|
111
|
-
}{{ "," if mixin_operations }}
|
|
112
|
-
{% if mixin_operations %}
|
|
113
|
-
"operation_mixins": {
|
|
114
|
-
"sync_imports": {{ str(sync_mixin_imports) | tojson }},
|
|
115
|
-
"async_imports": {{ str(async_mixin_imports) | tojson }},
|
|
116
|
-
"sync_mixin_typing_definitions": {{ str(sync_mixin_typing_definitions) | tojson }},
|
|
117
|
-
"async_mixin_typing_definitions": {{ str(async_mixin_typing_definitions) | tojson }},
|
|
118
|
-
"operations": {
|
|
119
|
-
{% for operation in mixin_operations %}
|
|
120
|
-
{{ operation.name | tojson }} : {
|
|
121
|
-
{% set request_builder = operation.request_builder %}
|
|
122
|
-
"sync": {
|
|
123
|
-
{% set operation_serializer = get_sync_operation_serializer(operation) %}
|
|
124
|
-
{% if is_lro(operation) and is_paging(operation) %}
|
|
125
|
-
{% from "lro_paging_operation.py.jinja2" import operation_docstring with context %}
|
|
126
|
-
{% set sync_return_type_wrapper = [operation.get_poller(async_mode=False), operation.get_pager(async_mode=False)] %}
|
|
127
|
-
{% elif is_lro(operation) %}
|
|
128
|
-
{% from "lro_operation.py.jinja2" import operation_docstring with context %}
|
|
129
|
-
{% set sync_return_type_wrapper = [operation.get_poller(async_mode=False)] %}
|
|
130
|
-
{% elif is_paging(operation) %}
|
|
131
|
-
{% from "paging_operation.py.jinja2" import operation_docstring with context %}
|
|
132
|
-
{% set sync_return_type_wrapper = [operation.get_pager(async_mode=False)] %}
|
|
133
|
-
{% else %}
|
|
134
|
-
{% from "operation.py.jinja2" import operation_docstring with context %}
|
|
135
|
-
{% set sync_return_type_wrapper = "" %}
|
|
136
|
-
{% endif %}
|
|
137
|
-
"signature": {{ (operation_serializer.method_signature_and_response_type_annotation(operation, want_decorators=False) + "\n") | tojson }},
|
|
138
|
-
"doc": {{ op_tools.description(operation, operation_serializer).rstrip("\n") | tojson }},
|
|
139
|
-
"call": {{ operation.parameters.call | join(', ') | tojson }}
|
|
140
|
-
},
|
|
141
|
-
"async": {
|
|
142
|
-
{% set coroutine = False if (is_paging(operation) and not is_lro(operation)) else True %}
|
|
143
|
-
{% set operation_serializer = get_async_operation_serializer(operation) %}
|
|
144
|
-
"coroutine": {{ coroutine | tojson }},
|
|
145
|
-
{% if is_lro(operation) and is_paging(operation) %}
|
|
146
|
-
{% from "lro_paging_operation.py.jinja2" import operation_docstring with context %}
|
|
147
|
-
{% set async_return_type_wrapper = [operation.get_poller(async_mode=True), operation.get_pager(async_mode=True)] %}
|
|
148
|
-
{% elif is_lro(operation) %}
|
|
149
|
-
{% from "lro_operation.py.jinja2" import operation_docstring with context %}
|
|
150
|
-
{% set async_return_type_wrapper = [operation.get_poller(async_mode=True)] %}
|
|
151
|
-
{% elif is_paging(operation) %}
|
|
152
|
-
{% from "paging_operation.py.jinja2" import operation_docstring with context %}
|
|
153
|
-
{% set async_return_type_wrapper = [operation.get_pager(async_mode=True)] %}
|
|
154
|
-
{% else %}
|
|
155
|
-
{% from "operation.py.jinja2" import operation_docstring with context %}
|
|
156
|
-
{% set async_return_type_wrapper = "" %}
|
|
157
|
-
{% endif %}
|
|
158
|
-
"signature": {{ (operation_serializer.method_signature_and_response_type_annotation(operation, want_decorators=False) + "\n") | tojson }},
|
|
159
|
-
"doc": {{ op_tools.description(operation, operation_serializer).rstrip("\n") | tojson }},
|
|
160
|
-
"call": {{ operation.parameters.call | join(', ') | tojson }}
|
|
161
|
-
}
|
|
162
|
-
}{{ "," if not loop.last else "" }}
|
|
163
|
-
{% endfor %}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
{% endif %}
|
|
167
|
-
}
|