Skip to content

Commit 8b3f0b8

Browse files
authored
[SchemaRegistry] generate GA SR from swagger (#21570)
fixes: #20661
1 parent e087039 commit 8b3f0b8

26 files changed

+801
-422
lines changed

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_common/_response_handlers.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,25 @@
2828

2929
def _parse_schema_properties_dict(response):
3030
return {
31-
'id': response.headers.get('schema-id'),
32-
'format': response.headers.get('serialization-type')
31+
'id': response.headers.get('schema-id')
3332
}
3433

3534

36-
def _parse_response_schema_properties(response):
35+
def _parse_response_schema_properties(response, format):
36+
# pylint:disable=redefined-builtin
3737
properties_dict = _parse_schema_properties_dict(response)
38-
properties_dict['id'] = response.json()["id"]
38+
properties_dict['format'] = format
3939
return SchemaProperties(
4040
**properties_dict
4141
)
4242

4343

4444
def _parse_response_schema(response):
45+
# pylint:disable=redefined-builtin
46+
schema_props_dict = _parse_schema_properties_dict(response)
47+
format = response.headers.get('content-type').split('serialization=')[1]
48+
schema_props_dict['format'] = format
4549
return Schema(
4650
definition=response.text(),
47-
properties=SchemaProperties(**_parse_schema_properties_dict(response))
51+
properties=SchemaProperties(**schema_props_dict)
4852
)

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_generated/_azure_schema_registry.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,37 @@
1616

1717
if TYPE_CHECKING:
1818
# pylint: disable=unused-import,ungrouped-imports
19-
from typing import Any, Dict
19+
from typing import Any, Dict, Optional
2020

2121
from azure.core.credentials import TokenCredential
2222
from azure.core.rest import HttpRequest, HttpResponse
2323

2424
class AzureSchemaRegistry(object):
25-
"""Azure Schema Registry is as a central schema repository, complete with support for versioning, management, compatibility checking, and RBAC.
25+
"""Azure Schema Registry is as a central schema repository, with support for versioning, management, compatibility checking, and RBAC.
2626
27-
:param credential: Credential needed for the client to connect to Azure.
28-
:type credential: ~azure.core.credentials.TokenCredential
2927
:param endpoint: The Schema Registry service endpoint, for example
30-
my-namespace.servicebus.windows.net.
28+
my-namespace.servicebus.windows.net.
3129
:type endpoint: str
30+
:param credential: Credential needed for the client to connect to Azure.
31+
:type credential: ~azure.core.credentials.TokenCredential
32+
:keyword api_version: Api Version. The default value is "2021-10". Note that overriding this
33+
default value may result in unsupported behavior.
34+
:paramtype api_version: str
3235
"""
3336

3437
def __init__(
3538
self,
36-
credential, # type: "TokenCredential"
3739
endpoint, # type: str
40+
credential, # type: "TokenCredential"
3841
**kwargs # type: Any
3942
):
4043
# type: (...) -> None
41-
base_url = 'https://{endpoint}'
42-
self._config = AzureSchemaRegistryConfiguration(credential, endpoint, **kwargs)
43-
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs)
44+
_endpoint = 'https://{endpoint}'
45+
self._config = AzureSchemaRegistryConfiguration(endpoint=endpoint, credential=credential, **kwargs)
46+
self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)
4447

45-
client_models = {} # type: Dict[str, Any]
46-
self._serialize = Serializer(client_models)
47-
self._deserialize = Deserializer(client_models)
48+
self._serialize = Serializer()
49+
self._deserialize = Deserializer()
4850
self._serialize.client_side_validation = False
4951

5052

@@ -59,17 +61,14 @@ def send_request(
5961
We have helper methods to create requests specific to this service in `azure.schemaregistry._generated.rest`.
6062
Use these helper methods to create the request you pass to this method.
6163
62-
>>> from azure.schemaregistry._generated.rest import schema
63-
>>> request = schema.build_get_by_id_request(schema_id, **kwargs)
64-
<HttpRequest [GET], url: '/$schemagroups/getSchemaById/{schema-id}'>
64+
>>> from azure.schemaregistry._generated.rest import schema_groups
65+
>>> request = schema_groups.build_list_request(**kwargs)
66+
<HttpRequest [GET], url: '/$schemaGroups'>
6567
>>> response = client.send_request(request)
6668
<HttpResponse: 200 OK>
6769
6870
For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart
6971
70-
For advanced cases, you can also create your own :class:`~azure.core.rest.HttpRequest`
71-
and pass it in.
72-
7372
:param request: The network request you want to make. Required.
7473
:type request: ~azure.core.rest.HttpRequest
7574
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
@@ -79,8 +78,9 @@ def send_request(
7978

8079
request_copy = deepcopy(request)
8180
path_format_arguments = {
82-
'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
81+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
8382
}
83+
8484
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
8585
return self._client.send_request(request_copy, **kwargs)
8686

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_generated/_configuration.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,32 @@ class AzureSchemaRegistryConfiguration(Configuration):
2626
Note that all parameters used to create this instance are saved as instance
2727
attributes.
2828
29-
:param credential: Credential needed for the client to connect to Azure.
30-
:type credential: ~azure.core.credentials.TokenCredential
3129
:param endpoint: The Schema Registry service endpoint, for example my-namespace.servicebus.windows.net.
3230
:type endpoint: str
31+
:param credential: Credential needed for the client to connect to Azure.
32+
:type credential: ~azure.core.credentials.TokenCredential
33+
:keyword api_version: Api Version. The default value is "2021-10". Note that overriding this default value may result in unsupported behavior.
34+
:paramtype api_version: str
3335
"""
3436

3537
def __init__(
3638
self,
37-
credential, # type: "TokenCredential"
3839
endpoint, # type: str
40+
credential, # type: "TokenCredential"
3941
**kwargs # type: Any
4042
):
4143
# type: (...) -> None
42-
if credential is None:
43-
raise ValueError("Parameter 'credential' must not be None.")
44+
super(AzureSchemaRegistryConfiguration, self).__init__(**kwargs)
45+
api_version = kwargs.pop('api_version', "2021-10") # type: str
46+
4447
if endpoint is None:
4548
raise ValueError("Parameter 'endpoint' must not be None.")
46-
super(AzureSchemaRegistryConfiguration, self).__init__(**kwargs)
49+
if credential is None:
50+
raise ValueError("Parameter 'credential' must not be None.")
4751

48-
self.credential = credential
4952
self.endpoint = endpoint
50-
self.api_version = "2020-09-01-preview"
53+
self.credential = credential
54+
self.api_version = api_version
5155
self.credential_scopes = kwargs.pop('credential_scopes', ['https://eventhubs.azure.net/.default'])
5256
kwargs.setdefault('sdk_moniker', 'azureschemaregistry/{}'.format(VERSION))
5357
self._configure(**kwargs)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# --------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# Code generated by Microsoft (R) AutoRest Code Generator.
5+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
6+
# --------------------------------------------------------------------------
7+
8+
9+
10+
11+
def _format_url_section(template, **kwargs):
12+
components = template.split("/")
13+
while components:
14+
try:
15+
return template.format(**kwargs)
16+
except KeyError as key:
17+
formatted_components = template.split("/")
18+
components = [
19+
c for c in formatted_components if "{}".format(key.args[0]) not in c
20+
]
21+
template = "/".join(components)

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_generated/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
VERSION = "1.0.0b3"
9+
VERSION = "1.0.0"

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_generated/aio/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@
88

99
from ._azure_schema_registry import AzureSchemaRegistry
1010
__all__ = ['AzureSchemaRegistry']
11+
12+
try:
13+
from ._patch import patch_sdk # type: ignore
14+
patch_sdk()
15+
except ImportError:
16+
pass

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_generated/aio/_azure_schema_registry.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# --------------------------------------------------------------------------
88

99
from copy import deepcopy
10-
from typing import Any, Awaitable, TYPE_CHECKING
10+
from typing import Any, Awaitable, Optional, TYPE_CHECKING
1111

1212
from azure.core import AsyncPipelineClient
1313
from azure.core.rest import AsyncHttpResponse, HttpRequest
@@ -22,28 +22,30 @@
2222
from azure.core.credentials_async import AsyncTokenCredential
2323

2424
class AzureSchemaRegistry:
25-
"""Azure Schema Registry is as a central schema repository, complete with support for versioning, management, compatibility checking, and RBAC.
25+
"""Azure Schema Registry is as a central schema repository, with support for versioning, management, compatibility checking, and RBAC.
2626
27-
:param credential: Credential needed for the client to connect to Azure.
28-
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
2927
:param endpoint: The Schema Registry service endpoint, for example
30-
my-namespace.servicebus.windows.net.
28+
my-namespace.servicebus.windows.net.
3129
:type endpoint: str
30+
:param credential: Credential needed for the client to connect to Azure.
31+
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
32+
:keyword api_version: Api Version. The default value is "2021-10". Note that overriding this
33+
default value may result in unsupported behavior.
34+
:paramtype api_version: str
3235
"""
3336

3437
def __init__(
3538
self,
36-
credential: "AsyncTokenCredential",
3739
endpoint: str,
40+
credential: "AsyncTokenCredential",
3841
**kwargs: Any
3942
) -> None:
40-
base_url = 'https://{endpoint}'
41-
self._config = AzureSchemaRegistryConfiguration(credential, endpoint, **kwargs)
42-
self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs)
43+
_endpoint = 'https://{endpoint}'
44+
self._config = AzureSchemaRegistryConfiguration(endpoint=endpoint, credential=credential, **kwargs)
45+
self._client = AsyncPipelineClient(base_url=_endpoint, config=self._config, **kwargs)
4346

44-
client_models = {} # type: Dict[str, Any]
45-
self._serialize = Serializer(client_models)
46-
self._deserialize = Deserializer(client_models)
47+
self._serialize = Serializer()
48+
self._deserialize = Deserializer()
4749
self._serialize.client_side_validation = False
4850

4951

@@ -57,17 +59,14 @@ def send_request(
5759
We have helper methods to create requests specific to this service in `azure.schemaregistry._generated.rest`.
5860
Use these helper methods to create the request you pass to this method.
5961
60-
>>> from azure.schemaregistry._generated.rest import schema
61-
>>> request = schema.build_get_by_id_request(schema_id, **kwargs)
62-
<HttpRequest [GET], url: '/$schemagroups/getSchemaById/{schema-id}'>
62+
>>> from azure.schemaregistry._generated.rest import schema_groups
63+
>>> request = schema_groups.build_list_request(**kwargs)
64+
<HttpRequest [GET], url: '/$schemaGroups'>
6365
>>> response = await client.send_request(request)
6466
<AsyncHttpResponse: 200 OK>
6567
6668
For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart
6769
68-
For advanced cases, you can also create your own :class:`~azure.core.rest.HttpRequest`
69-
and pass it in.
70-
7170
:param request: The network request you want to make. Required.
7271
:type request: ~azure.core.rest.HttpRequest
7372
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
@@ -77,8 +76,9 @@ def send_request(
7776

7877
request_copy = deepcopy(request)
7978
path_format_arguments = {
80-
'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
79+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
8180
}
81+
8282
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
8383
return self._client.send_request(request_copy, **kwargs)
8484

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_generated/aio/_configuration.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,31 @@ class AzureSchemaRegistryConfiguration(Configuration):
2424
Note that all parameters used to create this instance are saved as instance
2525
attributes.
2626
27-
:param credential: Credential needed for the client to connect to Azure.
28-
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
2927
:param endpoint: The Schema Registry service endpoint, for example my-namespace.servicebus.windows.net.
3028
:type endpoint: str
29+
:param credential: Credential needed for the client to connect to Azure.
30+
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
31+
:keyword api_version: Api Version. The default value is "2021-10". Note that overriding this default value may result in unsupported behavior.
32+
:paramtype api_version: str
3133
"""
3234

3335
def __init__(
3436
self,
35-
credential: "AsyncTokenCredential",
3637
endpoint: str,
38+
credential: "AsyncTokenCredential",
3739
**kwargs: Any
3840
) -> None:
39-
if credential is None:
40-
raise ValueError("Parameter 'credential' must not be None.")
41+
super(AzureSchemaRegistryConfiguration, self).__init__(**kwargs)
42+
api_version = kwargs.pop('api_version', "2021-10") # type: str
43+
4144
if endpoint is None:
4245
raise ValueError("Parameter 'endpoint' must not be None.")
43-
super(AzureSchemaRegistryConfiguration, self).__init__(**kwargs)
46+
if credential is None:
47+
raise ValueError("Parameter 'credential' must not be None.")
4448

45-
self.credential = credential
4649
self.endpoint = endpoint
47-
self.api_version = "2020-09-01-preview"
50+
self.credential = credential
51+
self.api_version = api_version
4852
self.credential_scopes = kwargs.pop('credential_scopes', ['https://eventhubs.azure.net/.default'])
4953
kwargs.setdefault('sdk_moniker', 'azureschemaregistry/{}'.format(VERSION))
5054
self._configure(**kwargs)

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_generated/rest/schema/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88

99
try:
1010
from ._request_builders_py3 import build_get_by_id_request
11+
from ._request_builders_py3 import build_get_versions_request
1112
from ._request_builders_py3 import build_query_id_by_content_request
1213
from ._request_builders_py3 import build_register_request
1314
except (SyntaxError, ImportError):
1415
from ._request_builders import build_get_by_id_request # type: ignore
16+
from ._request_builders import build_get_versions_request # type: ignore
1517
from ._request_builders import build_query_id_by_content_request # type: ignore
1618
from ._request_builders import build_register_request # type: ignore
1719

1820
__all__ = [
1921
'build_get_by_id_request',
22+
'build_get_versions_request',
2023
'build_query_id_by_content_request',
2124
'build_register_request',
2225
]

0 commit comments

Comments
 (0)