@typespec/http-client-python 0.12.1 → 0.12.3
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/README.md +6 -0
- package/dist/emitter/emitter.d.ts.map +1 -1
- package/dist/emitter/emitter.js +1 -0
- package/dist/emitter/emitter.js.map +1 -1
- package/dist/emitter/http.js +1 -1
- package/dist/emitter/http.js.map +1 -1
- package/dist/emitter/lib.d.ts.map +1 -1
- package/dist/emitter/lib.js +5 -0
- package/dist/emitter/lib.js.map +1 -1
- package/dist/emitter/types.d.ts.map +1 -1
- package/dist/emitter/types.js +1 -0
- package/dist/emitter/types.js.map +1 -1
- package/dist/emitter/utils.d.ts +1 -0
- package/dist/emitter/utils.d.ts.map +1 -1
- package/dist/emitter/utils.js +1 -0
- package/dist/emitter/utils.js.map +1 -1
- package/emitter/src/emitter.ts +1 -0
- package/emitter/src/http.ts +1 -1
- package/emitter/src/lib.ts +6 -0
- package/emitter/src/types.ts +1 -0
- package/emitter/src/utils.ts +2 -0
- package/emitter/temp/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/setup/__pycache__/venvtools.cpython-39.pyc +0 -0
- package/generator/build/lib/pygen/codegen/__init__.py +5 -0
- package/generator/build/lib/pygen/codegen/models/operation.py +3 -1
- package/generator/build/lib/pygen/codegen/models/parameter.py +1 -0
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +2 -0
- package/generator/build/lib/pygen/codegen/serializers/metadata_serializer.py +1 -1
- package/generator/build/lib/pygen/codegen/templates/validation.py.jinja2 +18 -2
- package/generator/build/lib/pygen/preprocess/__init__.py +1 -2
- package/generator/component-detection-pip-report.json +2 -2
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/__init__.py +5 -0
- package/generator/pygen/codegen/models/operation.py +3 -1
- package/generator/pygen/codegen/models/parameter.py +1 -0
- package/generator/pygen/codegen/serializers/builder_serializer.py +2 -0
- package/generator/pygen/codegen/serializers/metadata_serializer.py +1 -1
- package/generator/pygen/codegen/templates/validation.py.jinja2 +18 -2
- package/generator/pygen/preprocess/__init__.py +1 -2
- package/package.json +2 -2
- /package/generator/test/azure/mock_api_tests/{test_resiliency_srv_driven_async.py → asynctests/test_resiliency_srv_driven_async.py} +0 -0
|
@@ -81,6 +81,7 @@ class _ParameterBase(BaseModel, abc.ABC): # pylint: disable=too-many-instance-a
|
|
|
81
81
|
self.grouper: bool = self.yaml_data.get("grouper", False)
|
|
82
82
|
self.check_client_input: bool = self.yaml_data.get("checkClientInput", False)
|
|
83
83
|
self.added_on: Optional[str] = self.yaml_data.get("addedOn")
|
|
84
|
+
self.api_versions: Optional[List[str]] = self.yaml_data.get("apiVersions", [])
|
|
84
85
|
self.is_api_version: bool = self.yaml_data.get("isApiVersion", False)
|
|
85
86
|
self.in_overload: bool = self.yaml_data.get("inOverload", False)
|
|
86
87
|
self.default_to_unset_sentinel: bool = self.yaml_data.get("defaultToUnsetSentinel", False)
|
|
@@ -607,6 +607,8 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
|
|
|
607
607
|
if params_added_on:
|
|
608
608
|
retval.append(f" params_added_on={dict(params_added_on)},")
|
|
609
609
|
if retval:
|
|
610
|
+
if builder.api_versions:
|
|
611
|
+
retval.append(f" api_versions_list={builder.api_versions},")
|
|
610
612
|
retval_str = "\n".join(retval)
|
|
611
613
|
return f"@api_version_validation(\n{retval_str}\n)"
|
|
612
614
|
return ""
|
|
@@ -6,6 +6,22 @@ import functools
|
|
|
6
6
|
def api_version_validation(**kwargs):
|
|
7
7
|
params_added_on = kwargs.pop("params_added_on", {})
|
|
8
8
|
method_added_on = kwargs.pop("method_added_on", "")
|
|
9
|
+
api_versions_list = kwargs.pop("api_versions_list", [])
|
|
10
|
+
|
|
11
|
+
def _index_with_default(value: str, default: int = -1) -> int:
|
|
12
|
+
"""Get the index of value in lst, or return default if not found.
|
|
13
|
+
|
|
14
|
+
:param value: The value to search for in the api_versions_list.
|
|
15
|
+
:type value: str
|
|
16
|
+
:param default: The default value to return if the value is not found.
|
|
17
|
+
:type default: int
|
|
18
|
+
:return: The index of the value in the list, or the default value if not found.
|
|
19
|
+
:rtype: int
|
|
20
|
+
"""
|
|
21
|
+
try:
|
|
22
|
+
return api_versions_list.index(value)
|
|
23
|
+
except ValueError:
|
|
24
|
+
return default
|
|
9
25
|
|
|
10
26
|
def decorator(func):
|
|
11
27
|
@functools.wraps(func)
|
|
@@ -17,7 +33,7 @@ def api_version_validation(**kwargs):
|
|
|
17
33
|
except AttributeError:
|
|
18
34
|
return func(*args, **kwargs)
|
|
19
35
|
|
|
20
|
-
if method_added_on > client_api_version:
|
|
36
|
+
if _index_with_default(method_added_on) > _index_with_default(client_api_version):
|
|
21
37
|
raise ValueError(
|
|
22
38
|
f"'{func.__name__}' is not available in API version "
|
|
23
39
|
f"{client_api_version}. Pass service API version {method_added_on} or newer to your client."
|
|
@@ -27,7 +43,7 @@ def api_version_validation(**kwargs):
|
|
|
27
43
|
parameter: api_version
|
|
28
44
|
for api_version, parameters in params_added_on.items()
|
|
29
45
|
for parameter in parameters
|
|
30
|
-
if parameter in kwargs and api_version > client_api_version
|
|
46
|
+
if parameter in kwargs and _index_with_default(api_version) > _index_with_default(client_api_version)
|
|
31
47
|
}
|
|
32
48
|
if unsupported:
|
|
33
49
|
raise ValueError("".join([
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
"""The preprocessing autorest plugin.
|
|
7
|
-
"""
|
|
6
|
+
"""The preprocessing autorest plugin."""
|
|
8
7
|
import copy
|
|
9
8
|
from typing import Callable, Dict, Any, List, Optional
|
|
10
9
|
|
|
@@ -123,13 +123,13 @@
|
|
|
123
123
|
],
|
|
124
124
|
"environment": {
|
|
125
125
|
"implementation_name": "cpython",
|
|
126
|
-
"implementation_version": "3.9.
|
|
126
|
+
"implementation_version": "3.9.23",
|
|
127
127
|
"os_name": "posix",
|
|
128
128
|
"platform_machine": "x86_64",
|
|
129
129
|
"platform_release": "6.11.0-1015-azure",
|
|
130
130
|
"platform_system": "Linux",
|
|
131
131
|
"platform_version": "#15~24.04.1-Ubuntu SMP Thu May 1 02:52:08 UTC 2025",
|
|
132
|
-
"python_full_version": "3.9.
|
|
132
|
+
"python_full_version": "3.9.23",
|
|
133
133
|
"platform_python_implementation": "CPython",
|
|
134
134
|
"python_version": "3.9",
|
|
135
135
|
"sys_platform": "linux"
|
|
Binary file
|
|
@@ -109,6 +109,10 @@ class OptionsRetriever:
|
|
|
109
109
|
def package_pprint_name(self) -> str:
|
|
110
110
|
return self.options.get("package-pprint-name") or _default_pprint(str(self.package_name))
|
|
111
111
|
|
|
112
|
+
@property
|
|
113
|
+
def validate_versioning(self) -> bool:
|
|
114
|
+
return self.options.get("validate-versioning", True)
|
|
115
|
+
|
|
112
116
|
@property
|
|
113
117
|
def default_optional_constants_to_none(self) -> bool:
|
|
114
118
|
return self.options.get(
|
|
@@ -301,6 +305,7 @@ class CodeGenerator(Plugin):
|
|
|
301
305
|
"from_typespec",
|
|
302
306
|
"flavor",
|
|
303
307
|
"emit_cross_language_definition_file",
|
|
308
|
+
"validate_versioning",
|
|
304
309
|
]
|
|
305
310
|
return {f: getattr(self.options_retriever, f) for f in flags}
|
|
306
311
|
|
|
@@ -275,7 +275,9 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
275
275
|
@property
|
|
276
276
|
def need_validation(self) -> bool:
|
|
277
277
|
"""Whether we need parameter / operation validation. For API version."""
|
|
278
|
-
return
|
|
278
|
+
return self.code_model.options["validate_versioning"] and (
|
|
279
|
+
bool(self.added_on) or any(p for p in self.parameters if p.added_on)
|
|
280
|
+
)
|
|
279
281
|
|
|
280
282
|
def get_request_builder_import(
|
|
281
283
|
self,
|
|
@@ -81,6 +81,7 @@ class _ParameterBase(BaseModel, abc.ABC): # pylint: disable=too-many-instance-a
|
|
|
81
81
|
self.grouper: bool = self.yaml_data.get("grouper", False)
|
|
82
82
|
self.check_client_input: bool = self.yaml_data.get("checkClientInput", False)
|
|
83
83
|
self.added_on: Optional[str] = self.yaml_data.get("addedOn")
|
|
84
|
+
self.api_versions: Optional[List[str]] = self.yaml_data.get("apiVersions", [])
|
|
84
85
|
self.is_api_version: bool = self.yaml_data.get("isApiVersion", False)
|
|
85
86
|
self.in_overload: bool = self.yaml_data.get("inOverload", False)
|
|
86
87
|
self.default_to_unset_sentinel: bool = self.yaml_data.get("defaultToUnsetSentinel", False)
|
|
@@ -607,6 +607,8 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
|
|
|
607
607
|
if params_added_on:
|
|
608
608
|
retval.append(f" params_added_on={dict(params_added_on)},")
|
|
609
609
|
if retval:
|
|
610
|
+
if builder.api_versions:
|
|
611
|
+
retval.append(f" api_versions_list={builder.api_versions},")
|
|
610
612
|
retval_str = "\n".join(retval)
|
|
611
613
|
return f"@api_version_validation(\n{retval_str}\n)"
|
|
612
614
|
return ""
|
|
@@ -6,6 +6,22 @@ import functools
|
|
|
6
6
|
def api_version_validation(**kwargs):
|
|
7
7
|
params_added_on = kwargs.pop("params_added_on", {})
|
|
8
8
|
method_added_on = kwargs.pop("method_added_on", "")
|
|
9
|
+
api_versions_list = kwargs.pop("api_versions_list", [])
|
|
10
|
+
|
|
11
|
+
def _index_with_default(value: str, default: int = -1) -> int:
|
|
12
|
+
"""Get the index of value in lst, or return default if not found.
|
|
13
|
+
|
|
14
|
+
:param value: The value to search for in the api_versions_list.
|
|
15
|
+
:type value: str
|
|
16
|
+
:param default: The default value to return if the value is not found.
|
|
17
|
+
:type default: int
|
|
18
|
+
:return: The index of the value in the list, or the default value if not found.
|
|
19
|
+
:rtype: int
|
|
20
|
+
"""
|
|
21
|
+
try:
|
|
22
|
+
return api_versions_list.index(value)
|
|
23
|
+
except ValueError:
|
|
24
|
+
return default
|
|
9
25
|
|
|
10
26
|
def decorator(func):
|
|
11
27
|
@functools.wraps(func)
|
|
@@ -17,7 +33,7 @@ def api_version_validation(**kwargs):
|
|
|
17
33
|
except AttributeError:
|
|
18
34
|
return func(*args, **kwargs)
|
|
19
35
|
|
|
20
|
-
if method_added_on > client_api_version:
|
|
36
|
+
if _index_with_default(method_added_on) > _index_with_default(client_api_version):
|
|
21
37
|
raise ValueError(
|
|
22
38
|
f"'{func.__name__}' is not available in API version "
|
|
23
39
|
f"{client_api_version}. Pass service API version {method_added_on} or newer to your client."
|
|
@@ -27,7 +43,7 @@ def api_version_validation(**kwargs):
|
|
|
27
43
|
parameter: api_version
|
|
28
44
|
for api_version, parameters in params_added_on.items()
|
|
29
45
|
for parameter in parameters
|
|
30
|
-
if parameter in kwargs and api_version > client_api_version
|
|
46
|
+
if parameter in kwargs and _index_with_default(api_version) > _index_with_default(client_api_version)
|
|
31
47
|
}
|
|
32
48
|
if unsupported:
|
|
33
49
|
raise ValueError("".join([
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
"""The preprocessing autorest plugin.
|
|
7
|
-
"""
|
|
6
|
+
"""The preprocessing autorest plugin."""
|
|
8
7
|
import copy
|
|
9
8
|
from typing import Callable, Dict, Any, List, Optional
|
|
10
9
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/http-client-python",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "TypeSpec emitter for Python SDKs",
|
|
6
6
|
"homepage": "https://typespec.io",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"@azure-tools/typespec-azure-core": "~0.57.0",
|
|
82
82
|
"@azure-tools/typespec-azure-resource-manager": "~0.57.0",
|
|
83
83
|
"@azure-tools/typespec-azure-rulesets": "~0.57.0",
|
|
84
|
-
"@azure-tools/typespec-client-generator-core": "~0.57.
|
|
84
|
+
"@azure-tools/typespec-client-generator-core": "~0.57.1",
|
|
85
85
|
"@azure-tools/azure-http-specs": "0.1.0-alpha.19",
|
|
86
86
|
"@typespec/compiler": "^1.1.0",
|
|
87
87
|
"@typespec/http": "^1.1.0",
|