Skip to content

Commit 53a9c9a

Browse files
authored
[SchemaRegistry] update client for JSON/Custom GA (#36386)
* remove JsonSchemaDraftIdentifier * address apiview comments/remove protobuf * revert sample * mypy/pylint * rename MessageType + black * re-gen for api version 2022-10 * readme + changelog * update test recordings for api_version 2022-10 * update version
1 parent f812aaa commit 53a9c9a

35 files changed

+400
-728
lines changed

sdk/schemaregistry/azure-schemaregistry/CHANGELOG.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
# Release History
22

3-
## 1.3.0b4 (Unreleased)
3+
## 1.3.0 (Unreleased)
4+
5+
This version and all future versions will require Python 3.8+. Python 3.7 is no longer supported.
46

57
### Features Added
68

7-
### Breaking Changes
9+
- `V2022_10` has been added to `ApiVersion` and set as the default API version.
10+
- `Json` and `Custom` have been added to supported formats in `SchemaFormat`.
11+
- Sync and async `JsonSchemaEncoder` have been added under `azure.schemaregistry.encoder.jsonencoder`.
12+
- `InvalidContentError` have been added under `azure.schemaregistry.encoder.jsonencoder` for use with the `JsonSchemaEncoder`.
13+
- `MessageContent`, `OutboundMessageContent`,`InboundMessageContent`, and `SchemaContentValidate` have been added under `azure.schemaregistry` as protocols for use with the `JsonSchemaEncoder` and/or future encoder implementations.
814

915
### Bugs Fixed
1016

17+
- Fixed a bug in sync/async `register_schema` and `get_schema_properties` that did not accept case insensitive strings as an argument to the `format` parameter.
18+
1119
### Other Changes
1220

1321
- Updated azure-core minimum dependency to 1.28.0.
22+
- Added support for Python 3.11 and 3.12.
23+
- The following features have been temporarily pulled out and will be added back in future previews as we work towards a stable release:
24+
- `V2023_07_01` in `ApiVersion`.
25+
- `PROTOBUF` in `SchemaFormat`.
1426

1527
## 1.3.0b3 (2023-11-09)
1628

1729
### Features Added
1830

19-
- `V2023_07_01` has been added to `ApiVersion` and set as the default api version.
31+
- `V2023_07_01` has been added to `ApiVersion` and set as the default API version.
2032
- `Protobuf` has been added to supported formats in `SchemaFormat`.
2133

2234
### Other Changes

sdk/schemaregistry/azure-schemaregistry/README.md

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ _Azure SDK Python packages support for Python 2.7 has ended on 01 January 2022.
2727
Install the Azure Schema Registry client library for Python with [pip][pip]:
2828

2929
```Bash
30-
pip install azure-schemaregistry==1.3.0b2
30+
pip install azure-schemaregistry
3131
```
3232

3333
To use the built-in `jsonschema` validators with the JSON Schema Encoder, install `jsonencoder` extras:
3434

3535
```Bash
36-
pip install azure-schemaregistry[jsonencoder]==1.3.0b2
36+
pip install azure-schemaregistry[jsonencoder]
3737
```
3838

3939
### Prerequisites:
4040
To use this package, you must have:
4141
* Azure subscription - [Create a free account][azure_sub]
4242
* [Azure Schema Registry][schemaregistry_service] - [Here is the quickstart guide][quickstart_guide] to create a Schema Registry group using the Azure portal.
43-
* Python 3.7 or later - [Install Python][python]
43+
* Python 3.8 or later - [Install Python][python]
4444

4545
### Authenticate the client
4646

@@ -91,20 +91,27 @@ encoder = JsonSchemaEncoder(client=schema_registry_client, group_name=group_name
9191

9292
## Key concepts
9393

94+
### Client concepts
95+
9496
* Schema: Schema is the organization or structure for data. More detailed information can be found [here][schemas].
9597

9698
* Schema Group: A logical group of similar schemas based on business criteria, which can hold multiple versions of a schema. More detailed information can be found [here][schema_groups].
9799

98100
* SchemaRegistryClient: `SchemaRegistryClient` provides the API for storing and retrieving schemas in schema registry.
99101

102+
### Encoder concepts
103+
100104
* JsonSchemaEncoder: Provides API to encode content to and decode content from Binary Encoding, validate content against a JSON Schema, and cache schemas/schema IDs retrived from the registry using the `SchemaRegistryClient` locally.
101105

102-
* MessageType: Protocol defined under `azure.schemaregistry` that allows for `JsonSchemaEncoder` interoperability with certain Azure Messaging SDK message types. Support has been added to:
106+
* OutboundMessageContent: Protocol defined under `azure.schemaregistry` that allows for `JsonSchemaEncoder.encode` interoperability with certain Azure Messaging SDK message types. Support has been added to:
107+
* `azure.eventhub.EventData` for `azure-eventhub>=5.9.0`
108+
109+
* InboundMessageContent: Protocol defined under `azure.schemaregistry` that allows for `JsonSchemaEncoder.decode` interoperability with certain Azure Messaging SDK message types. Support has been added to:
103110
* `azure.eventhub.EventData` for `azure-eventhub>=5.9.0`
104111

105-
### MessageType
112+
#### OutboundMessageContent/InboundMessageContent
106113

107-
If a message type that follows the MessageType protocol is provided to the encoder, it will set the corresponding content and content type properties:
114+
If a message type that follows the OutboundMessageContent protocol is provided to the `JsonSchemaEncoder`, it will set the corresponding content and content type properties. If a message type object that follows the InboundMessageContent protocol is provided to the encoder, it will get the corresponding content and content type properties. These are defined as:
108115

109116
* `content`: Binary-encoded, JSON schema-validated payload (in general, format-specific payload)
110117

@@ -253,15 +260,17 @@ The `encode` method automatically retrieves the schema from the Schema Registry
253260

254261
```python
255262
import os
263+
import json
256264
from azure.schemaregistry import SchemaRegistryClient, SchemaFormat
257-
from azure.schemaregistry.encoder.jsonencoder import JsonSchemaEncoder, JsonSchemaDraftIdentifier
265+
from azure.schemaregistry.encoder.jsonencoder import JsonSchemaEncoder
258266
from azure.identity import DefaultAzureCredential
259267
from azure.eventhub import EventData
260268

261269
token_credential = DefaultAzureCredential()
262270
fully_qualified_namespace = os.environ['SCHEMAREGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE']
263271
group_name = os.environ['SCHEMAREGISTRY_GROUP']
264272
format = SchemaFormat.JSON
273+
DRAFT2020_12_SCHEMA_IDENTIFIER = "https://json-schema.org/draft/2020-12/schema"
265274

266275
schema = {
267276
"$id": "https://example.com/person.schema.json",
@@ -291,7 +300,7 @@ schema_properties = schema_registry_client.register_schema(group_name, name, def
291300
schema_id = schema_properties.id
292301

293302
# group_name only needed if passing `schema` to encode
294-
encoder = JsonSchemaEncoder(client=schema_registry_client, validate=JsonSchemaDraftIdentifier.DRAFT2020_12, group_name=group_name)
303+
encoder = JsonSchemaEncoder(client=schema_registry_client, validate=DRAFT2020_12_SCHEMA_IDENTIFIER, group_name=group_name)
295304

296305
with encoder:
297306
dict_content = {"name": "Ben", "favorite_number": 7, "favorite_color": "red"}
@@ -317,15 +326,16 @@ The `decode` method automatically retrieves the schema from the Schema Registry
317326
```python
318327
import os
319328
from azure.schemaregistry import SchemaRegistryClient
320-
from azure.schemaregistry.encoder.jsonencoder import JsonSchemaEncoder, JsonSchemaDraftIdentifier
329+
from azure.schemaregistry.encoder.jsonencoder import JsonSchemaEncoder
321330
from azure.identity import DefaultAzureCredential
322331

323332
token_credential = DefaultAzureCredential()
324333
fully_qualified_namespace = os.environ['SCHEMAREGISTRY_FULLY_QUALIFIED_NAMESPACE']
325334
group_name = os.environ["SCHEMAREGISTRY_GROUP"]
335+
DRAFT2020_12_SCHEMA_IDENTIFIER = "https://json-schema.org/draft/2020-12/schema"
326336

327337
schema_registry_client = SchemaRegistryClient(fully_qualified_namespace, token_credential)
328-
encoder = JsonSchemaEncoder(client=schema_registry_client, validate=JsonSchemaDraftIdentifier.DRAFT2020_12)
338+
encoder = JsonSchemaEncoder(client=schema_registry_client, validate=DRAFT2020_12_SCHEMA_IDENTIFIER)
329339

330340
with encoder:
331341
# event_data is an EventData object with encoded body
@@ -345,7 +355,7 @@ Integration with [Event Hubs][eventhubs_repo] to send an `EventData` object with
345355
import os
346356
from azure.eventhub import EventHubProducerClient, EventData
347357
from azure.schemaregistry import SchemaRegistryClient
348-
from azure.schemaregistry.encoder.jsonencoder import JsonSchemaEncoder, JsonSchemaDraftIdentifier
358+
from azure.schemaregistry.encoder.jsonencoder import JsonSchemaEncoder
349359
from azure.identity import DefaultAzureCredential
350360

351361
token_credential = DefaultAzureCredential()
@@ -355,9 +365,10 @@ eventhub_connection_str = os.environ['EVENT_HUB_CONN_STR']
355365
eventhub_name = os.environ['EVENT_HUB_NAME']
356366

357367
schema_id = os.environ['PERSON_JSON_SCHEMA_ID']
368+
DRAFT2020_12_SCHEMA_IDENTIFIER = "https://json-schema.org/draft/2020-12/schema"
358369

359370
schema_registry_client = SchemaRegistryClient(fully_qualified_namespace, token_credential)
360-
json_schema_encoder = JsonSchemaEncoder(client=schema_registry_client, validate=JsonSchemaDraftIdentifier.DRAFT2020_12)
371+
json_schema_encoder = JsonSchemaEncoder(client=schema_registry_client, validate=DRAFT2020_12_SCHEMA_IDENTIFIER)
361372

362373
eventhub_producer = EventHubProducerClient.from_connection_string(
363374
conn_str=eventhub_connection_str,
@@ -380,17 +391,18 @@ Integration with [Event Hubs][eventhubs_repo] to receive an `EventData` object a
380391
import os
381392
from azure.eventhub import EventHubConsumerClient
382393
from azure.schemaregistry import SchemaRegistryClient
383-
from azure.schemaregistry.encoder.jsonencoder import JsonSchemaEncoder, JsonSchemaDraftIdentifier
394+
from azure.schemaregistry.encoder.jsonencoder import JsonSchemaEncoder
384395
from azure.identity import DefaultAzureCredential
385396

386397
token_credential = DefaultAzureCredential()
387-
fully_qualified_namespace = os.environ['SCHEMAREGISTRY_FULLY_QUALIFIED_NAMESPACE']
398+
fully_qualified_namespace = os.environ['SCHEMAREGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE']
388399
group_name = os.environ['SCHEMAREGISTRY_GROUP']
389400
eventhub_connection_str = os.environ['EVENT_HUB_CONN_STR']
390401
eventhub_name = os.environ['EVENT_HUB_NAME']
402+
DRAFT2020_12_SCHEMA_IDENTIFIER = "https://json-schema.org/draft/2020-12/schema"
391403

392404
schema_registry_client = SchemaRegistryClient(fully_qualified_namespace, token_credential)
393-
json_schema_encoder = JsonSchemaEncoder(client=schema_registry_client, validate=JsonSchemaDraftIdentifier.DRAFT2020_12)
405+
json_schema_encoder = JsonSchemaEncoder(client=schema_registry_client, validate=DRAFT2020_12_SCHEMA_IDENTIFIER)
394406

395407
eventhub_consumer = EventHubConsumerClient.from_connection_string(
396408
conn_str=eventhub_connection_str,
@@ -427,7 +439,7 @@ import sys
427439
import os
428440
import logging
429441
from azure.schemaregistry import SchemaRegistryClient
430-
from azure.schemaregistry.encoder.jsonencoder import JsonSchemaEncoder, JsonSchemaDraftIdentifier
442+
from azure.schemaregistry.encoder.jsonencoder import JsonSchemaEncoder
431443
from azure.identity import DefaultAzureCredential
432444

433445
# Create a logger for the SDK
@@ -440,10 +452,11 @@ logger.addHandler(handler)
440452

441453
fully_qualified_namespace = os.environ['SCHEMAREGISTRY_FULLY_QUALIFIED_NAMESPACE']
442454
group_name = os.environ['SCHEMAREGISTRY_GROUP']
455+
DRAFT2020_12_SCHEMA_IDENTIFIER = "https://json-schema.org/draft/2020-12/schema"
443456
credential = DefaultAzureCredential()
444457
# This client will log detailed information about its HTTP sessions, at DEBUG level
445458
schema_registry_client = SchemaRegistryClient(fully_qualified_namespace, credential, logging_enable=True)
446-
encoder = JsonSchemaEncoder(client=schema_registry_client, validate=JsonSchemaDraftIdentifier.DRAFT2020_12)
459+
encoder = JsonSchemaEncoder(client=schema_registry_client, validate=DRAFT2020_12_SCHEMA_IDENTIFIER)
447460
```
448461

449462
Similarly, `logging_enable` can enable detailed logging for a single operation,

sdk/schemaregistry/azure-schemaregistry/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/schemaregistry/azure-schemaregistry",
5-
"Tag": "python/schemaregistry/azure-schemaregistry_88eea61cd4"
5+
"Tag": "python/schemaregistry/azure-schemaregistry_a1c9d18bfd"
66
}

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SchemaRegistryClient(SchemaRegistryClientOperationsMixin): # pylint: disa
3232
:type fully_qualified_namespace: str
3333
:param credential: Credential used to authenticate requests to the service. Required.
3434
:type credential: ~azure.core.credentials.TokenCredential
35-
:keyword api_version: The API version to use for this operation. Default value is "2023-07-01".
35+
:keyword api_version: The API version to use for this operation. Default value is "2022-10".
3636
Note that overriding this default value may result in unsupported behavior.
3737
:paramtype api_version: str
3838
"""

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ class SchemaRegistryClientConfiguration: # pylint: disable=too-many-instance-at
2828
:type fully_qualified_namespace: str
2929
:param credential: Credential used to authenticate requests to the service. Required.
3030
:type credential: ~azure.core.credentials.TokenCredential
31-
:keyword api_version: The API version to use for this operation. Default value is "2023-07-01".
31+
:keyword api_version: The API version to use for this operation. Default value is "2022-10".
3232
Note that overriding this default value may result in unsupported behavior.
3333
:paramtype api_version: str
3434
"""
3535

3636
def __init__(self, fully_qualified_namespace: str, credential: "TokenCredential", **kwargs: Any) -> None:
37-
api_version: str = kwargs.pop("api_version", "2023-07-01")
37+
api_version: str = kwargs.pop("api_version", "2022-10")
3838

3939
if fully_qualified_namespace is None:
4040
raise ValueError("Parameter 'fully_qualified_namespace' must not be None.")

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_operations/_operations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def build_schema_registry_list_schema_groups_request(**kwargs: Any) -> HttpReque
4343
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
4444
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
4545

46-
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2023-07-01"))
46+
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-10"))
4747
accept = _headers.pop("Accept", "application/json")
4848

4949
# Construct URL
@@ -64,7 +64,7 @@ def build_schema_registry_list_schema_versions_request( # pylint: disable=name-
6464
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
6565
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
6666

67-
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2023-07-01"))
67+
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-10"))
6868
accept = _headers.pop("Accept", "application/json")
6969

7070
# Construct URL
@@ -91,7 +91,7 @@ def build_schema_registry_get_schema_by_id_request( # pylint: disable=name-too-
9191
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
9292
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
9393

94-
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2023-07-01"))
94+
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-10"))
9595
accept = _headers.pop("Accept", "application/json; serialization=Avro")
9696
# Construct URL
9797
_url = "/$schemaGroups/$schemas/{id}"
@@ -116,7 +116,7 @@ def build_schema_registry_get_schema_by_version_request( # pylint: disable=name
116116
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
117117
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
118118

119-
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2023-07-01"))
119+
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-10"))
120120
accept = _headers.pop("Accept", "application/json; serialization=Avro")
121121
# Construct URL
122122
_url = "/$schemaGroups/{groupName}/schemas/{schemaName}/versions/{schemaVersion}"

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_operations/_patch.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
from azure.core.utils import case_insensitive_dict
2121
from azure.core.tracing.decorator import distributed_trace
2222

23-
from ._operations import ClsType, SchemaRegistryClientOperationsMixin as GeneratedClientOperationsMixin
23+
from ._operations import (
24+
ClsType,
25+
SchemaRegistryClientOperationsMixin as GeneratedClientOperationsMixin,
26+
)
2427
from .._serialization import Serializer
2528

2629
if TYPE_CHECKING:
@@ -143,7 +146,10 @@ def _get_schema_properties_by_content( # pylint: disable=inconsistent-return-st
143146
)
144147
path_format_arguments = {
145148
"fullyQualifiedNamespace": self._serialize.url(
146-
"self._config.fully_qualified_namespace", self._config.fully_qualified_namespace, "str", skip_quote=True
149+
"self._config.fully_qualified_namespace",
150+
self._config.fully_qualified_namespace,
151+
"str",
152+
skip_quote=True,
147153
),
148154
}
149155
request.url = self._client.format_url(request.url, **path_format_arguments)
@@ -224,7 +230,10 @@ def _register_schema( # pylint: disable=inconsistent-return-statements
224230
)
225231
path_format_arguments = {
226232
"fullyQualifiedNamespace": self._serialize.url(
227-
"self._config.fully_qualified_namespace", self._config.fully_qualified_namespace, "str", skip_quote=True
233+
"self._config.fully_qualified_namespace",
234+
self._config.fully_qualified_namespace,
235+
"str",
236+
skip_quote=True,
228237
),
229238
}
230239
request.url = self._client.format_url(request.url, **path_format_arguments)

0 commit comments

Comments
 (0)