Skip to content

Commit ed3138b

Browse files
authored
[SchemaRegistry] final api review changes (#21589)
1 parent c44fa5b commit ed3138b

File tree

14 files changed

+142
-112
lines changed

14 files changed

+142
-112
lines changed

sdk/schemaregistry/azure-schemaregistry/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313
- `SchemaProperties` has the following instance variables: `id`, `format`, `version`.
1414
- `Schema` has the following properties: `properties` and `schema_definition`.
1515
- `SchemaFormat` provides the schema format to be stored by the service. Currently, the only supported format is `Avro`.
16+
- `api_version` has been added as a keyword arg to the sync and async `SchemaRegistryClient` constructors
1617

1718
### Breaking Changes
1819

20+
- `version` instance variable in `SchemaProperties` has been removed.
21+
- `schema_definition` instance variable in `Schema` has been renamed `definition`.
22+
- `id` parameter in `get_schema` method on sync and async `SchemaRegistryClient` has been renamed `schema_id`.
23+
- `name` parameter in `register_schema` and `get_schema_properties` methods on sync and async `SchemaRegistryClient` has been renamed `schema_name`.
24+
1925
### Bugs Fixed
2026

2127
### Other Changes

sdk/schemaregistry/azure-schemaregistry/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ from azure.schemaregistry import SchemaRegistryClient
8686
token_credential = DefaultAzureCredential()
8787
fully_qualified_namespace = os.environ['SCHEMA_REGISTRY_FULLY_QUALIFIED_NAMESPACE']
8888
group_name = os.environ['SCHEMA_REGISTRY_GROUP']
89-
name = "your-schema-name"
89+
schema_name = "your-schema-name"
9090
format = "Avro"
9191
schema_definition = """
9292
{"namespace": "example.avro",
@@ -102,7 +102,7 @@ schema_definition = """
102102

103103
schema_registry_client = SchemaRegistryClient(fully_qualified_namespace=fully_qualified_namespace, credential=token_credential)
104104
with schema_registry_client:
105-
schema_properties = schema_registry_client.register_schema(group_name, name, schema_definition, format)
105+
schema_properties = schema_registry_client.register_schema(group_name, schema_name, schema_definition, format)
106106
id = schema_properties.id
107107
```
108108

@@ -118,12 +118,13 @@ from azure.schemaregistry import SchemaRegistryClient
118118

119119
token_credential = DefaultAzureCredential()
120120
fully_qualified_namespace = os.environ['SCHEMA_REGISTRY_FULLY_QUALIFIED_NAMESPACE']
121-
id = 'your-schema-id'
121+
schema_id = 'your-schema-id'
122122

123123
schema_registry_client = SchemaRegistryClient(fully_qualified_namespace=fully_qualified_namespace, credential=token_credential)
124124
with schema_registry_client:
125-
schema = schema_registry_client.get_schema(id)
126-
schema_definition = schema.schema_definition
125+
schema = schema_registry_client.get_schema(schema_id)
126+
definition = schema.definition
127+
properties = schema.properties
127128
```
128129

129130
### Get the id of a schema
@@ -139,7 +140,7 @@ from azure.schemaregistry import SchemaRegistryClient
139140
token_credential = DefaultAzureCredential()
140141
fully_qualified_namespace = os.environ['SCHEMA_REGISTRY_FULLY_QUALIFIED_NAMESPACE']
141142
group_name = os.environ['SCHEMA_REGISTRY_GROUP']
142-
name = "your-schema-name"
143+
schema_name = "your-schema-name"
143144
format = "Avro"
144145
schema_definition = """
145146
{"namespace": "example.avro",
@@ -155,7 +156,7 @@ schema_definition = """
155156

156157
schema_registry_client = SchemaRegistryClient(fully_qualified_namespace=fully_qualified_namespace, credential=token_credential)
157158
with schema_registry_client:
158-
schema_properties = schema_registry_client.register_schema(group_name, name, schema_definition, format)
159+
schema_properties = schema_registry_client.register_schema(group_name, schema_name, schema_definition, format)
159160
id = schema_properties.id
160161
```
161162

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
__version__ = VERSION
2828

2929
from ._schema_registry_client import SchemaRegistryClient
30-
from ._common._constants import SchemaFormat
30+
from ._common._constants import SchemaFormat, ApiVersion
3131
from ._common._schema import Schema, SchemaProperties
3232

3333
__all__ = [
34+
"ApiVersion",
3435
"SchemaRegistryClient",
3536
"SchemaFormat",
3637
"Schema",

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,14 @@ class SchemaFormat(str, Enum):
3333

3434
AVRO = "avro"
3535
"""Represents the Apache Avro schema format."""
36+
37+
class ApiVersion(str, Enum):
38+
"""
39+
Represents the Schema Registry API version to use for requests.
40+
"""
41+
42+
V2021_10 = "2021-10"
43+
"""This is the default version."""
44+
45+
46+
DEFAULT_VERSION = ApiVersion.V2021_10

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
def _parse_schema_properties_dict(response):
3030
return {
3131
'id': response.headers.get('schema-id'),
32-
'format': response.headers.get('serialization-type'),
33-
'version': int(response.headers.get('schema-version'))
32+
'format': response.headers.get('serialization-type')
3433
}
3534

3635

@@ -44,6 +43,6 @@ def _parse_response_schema_properties(response):
4443

4544
def _parse_response_schema(response):
4645
return Schema(
47-
schema_definition=response.text(),
46+
definition=response.text(),
4847
properties=SchemaProperties(**_parse_schema_properties_dict(response))
4948
)

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,29 @@ def __init__(self, **kwargs):
4242
# type: (Any) -> None
4343
self.id = kwargs.pop("id")
4444
self.format = kwargs.pop("format")
45-
self.version = kwargs.pop("version")
4645

4746
def __repr__(self):
48-
return "SchemaProperties(id={}, format={}, version={})".format(
49-
self.id, self.format, self.version
47+
return "SchemaProperties(id={}, format={})".format(
48+
self.id, self.format
5049
)[:1024]
5150

5251

5352
class Schema(object):
5453
"""
5554
The schema content of a schema, along with id and meta properties.
5655
57-
:ivar schema_definition: The content of the schema.
58-
:vartype schema_definition: str
56+
:ivar definition: The content of the schema.
57+
:vartype definition: str
5958
:ivar properties: The properties of the schema.
6059
:vartype properties: SchemaProperties
6160
"""
6261

6362
def __init__(self, **kwargs):
6463
# type: (Any) -> None
65-
self.schema_definition = kwargs.pop("schema_definition")
64+
self.definition = kwargs.pop("definition")
6665
self.properties = kwargs.pop("properties")
6766

6867
def __repr__(self):
69-
return "Schema(schema_definition={}, properties={})".format(
70-
self.schema_definition, self.properties
68+
return "Schema(definition={}, properties={})".format(
69+
self.definition, self.properties
7170
)[:1024]

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_schema_registry_client.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from typing import Any, TYPE_CHECKING, Union
2727

2828
from ._utils import get_http_request_kwargs
29-
from ._common._constants import SchemaFormat
29+
from ._common._constants import SchemaFormat, DEFAULT_VERSION
3030
from ._common._schema import Schema, SchemaProperties
3131
from ._common._response_handlers import (
3232
_parse_response_schema,
@@ -48,6 +48,8 @@ class SchemaRegistryClient(object):
4848
For example: my-namespace.servicebus.windows.net.
4949
:param credential: To authenticate managing the entities of the SchemaRegistry namespace.
5050
:type credential: ~azure.core.credentials.TokenCredential
51+
:keyword str api_version: The Schema Registry service API version to use for requests.
52+
Default value and only accepted value currently is "2021-10".
5153
5254
.. admonition:: Example:
5355
@@ -62,8 +64,12 @@ class SchemaRegistryClient(object):
6264

6365
def __init__(self, fully_qualified_namespace, credential, **kwargs):
6466
# type: (str, TokenCredential, Any) -> None
67+
api_version = kwargs.pop("api_version", DEFAULT_VERSION)
6568
self._generated_client = AzureSchemaRegistry(
66-
credential=credential, endpoint=fully_qualified_namespace, **kwargs
69+
credential=credential,
70+
endpoint=fully_qualified_namespace,
71+
api_version=api_version,
72+
**kwargs
6773
)
6874

6975
def __enter__(self):
@@ -83,7 +89,12 @@ def close(self):
8389
self._generated_client.close()
8490

8591
def register_schema(
86-
self, group_name, name, schema_definition, format, **kwargs # pylint:disable=redefined-builtin
92+
self,
93+
group_name,
94+
schema_name,
95+
schema_definition,
96+
format,
97+
**kwargs # pylint:disable=redefined-builtin
8798
):
8899
# type: (str, str, str, Union[str, SchemaFormat], Any) -> SchemaProperties
89100
"""
@@ -92,7 +103,7 @@ def register_schema(
92103
schema is created at latest version + 1.
93104
94105
:param str group_name: Schema group under which schema should be registered.
95-
:param str name: Name of schema being registered.
106+
:param str schema_name: Name of schema being registered.
96107
:param str schema_definition: String representation of the schema being registered.
97108
:param format: Format for the schema being registered.
98109
For now Avro is the only supported schema format by the service.
@@ -118,7 +129,7 @@ def register_schema(
118129
http_request_kwargs = get_http_request_kwargs(kwargs)
119130
request = schema_rest.build_register_request(
120131
group_name=group_name,
121-
schema_name=name,
132+
schema_name=schema_name,
122133
content=schema_definition,
123134
serialization_type=format,
124135
content_type=kwargs.pop("content_type", "application/json"),
@@ -129,13 +140,13 @@ def register_schema(
129140
response.raise_for_status()
130141
return _parse_response_schema_properties(response)
131142

132-
def get_schema(self, id, **kwargs): # pylint:disable=redefined-builtin
143+
def get_schema(self, schema_id, **kwargs):
133144
# type: (str, Any) -> Schema
134145
"""
135146
Gets a registered schema by its unique ID.
136147
Azure Schema Registry guarantees that ID is unique within a namespace.
137148
138-
:param str id: References specific schema in registry namespace.
149+
:param str schema_id: References specific schema in registry namespace.
139150
:rtype: ~azure.schemaregistry.Schema
140151
:raises: :class:`~azure.core.exceptions.HttpResponseError`
141152
@@ -150,21 +161,28 @@ def get_schema(self, id, **kwargs): # pylint:disable=redefined-builtin
150161
151162
"""
152163
http_request_kwargs = get_http_request_kwargs(kwargs)
153-
request = schema_rest.build_get_by_id_request(schema_id=id, **http_request_kwargs)
164+
request = schema_rest.build_get_by_id_request(
165+
schema_id=schema_id, **http_request_kwargs
166+
)
154167
response = self._generated_client.send_request(request, **kwargs)
155168
response.raise_for_status()
156169
return _parse_response_schema(response)
157170

158171
def get_schema_properties(
159-
self, group_name, name, schema_definition, format, **kwargs # pylint:disable=redefined-builtin
172+
self,
173+
group_name,
174+
schema_name,
175+
schema_definition,
176+
format,
177+
**kwargs # pylint:disable=redefined-builtin
160178
):
161179
# type: (str, str, str, Union[str, SchemaFormat], Any) -> SchemaProperties
162180
"""
163181
Gets the schema properties corresponding to an existing schema within the specified schema group,
164182
as matched by schema definition comparison.
165183
166184
:param str group_name: Schema group under which schema should be registered.
167-
:param str name: Name of schema being registered.
185+
:param str schema_name: Name of schema being registered.
168186
:param str schema_definition: String representation of the schema being registered.
169187
:param format: Format for the schema being registered.
170188
:type format: Union[str, SchemaFormat]
@@ -189,7 +207,7 @@ def get_schema_properties(
189207
http_request_kwargs = get_http_request_kwargs(kwargs)
190208
request = schema_rest.build_query_id_by_content_request(
191209
group_name=group_name,
192-
schema_name=name,
210+
schema_name=schema_name,
193211
content=schema_definition,
194212
serialization_type=format,
195213
content_type=kwargs.pop("content_type", "application/json"),

0 commit comments

Comments
 (0)