2222 overload ,
2323 IO ,
2424)
25+ from enum import Enum
2526from typing_extensions import Protocol , TypedDict , Self
26-
27+ from azure . core import CaseInsensitiveEnumMeta
2728from azure .core .tracing .decorator import distributed_trace
2829
2930from ._client import SchemaRegistryClient as GeneratedServiceClient
30- from .models ._patch import SchemaFormat
31+ from .models ._patch import SchemaFormat , NormalizedSchemaContentTypes
3132
3233if TYPE_CHECKING :
3334 from azure .core .credentials import TokenCredential
@@ -57,22 +58,24 @@ def _parse_schema_properties_dict(response_headers: Mapping[str, Union[str, int]
5758 "version" : int (response_headers ["Schema-Version" ]),
5859 }
5960
61+ def _normalize_content_type (content_type : str ) -> str :
62+ return content_type .replace (" " , "" ).lower ()
6063
61- def _get_format (content_type : str ) -> SchemaFormat :
64+ def _get_format (content_type : str ) -> Union [ SchemaFormat , str ] :
6265 # pylint:disable=redefined-builtin
6366 # Exception cases may be due to forward compatibility.
6467 # i.e. Getting a schema with a content type from a future API version.
65- # In this case, we default to CUSTOM format .
66- try :
67- format = content_type . split ( "serialization=" )[ 1 ]
68- try :
69- return SchemaFormat ( format . capitalize ())
70- except ValueError :
71- pass
72- except IndexError :
73- pass
74- return SchemaFormat .CUSTOM
75-
68+ # In this case, we default to returning the content type string .
69+
70+ # remove whitespace and case from string
71+ normalized_content_type = _normalize_content_type ( content_type )
72+ if normalized_content_type == NormalizedSchemaContentTypes . AVRO . value :
73+ return SchemaFormat . AVRO
74+ if normalized_content_type == NormalizedSchemaContentTypes . JSON . value :
75+ return SchemaFormat . JSON
76+ if normalized_content_type == NormalizedSchemaContentTypes . CUSTOM . value :
77+ return SchemaFormat .CUSTOM
78+ return content_type
7679
7780def prepare_schema_properties_result ( # pylint:disable=unused-argument,redefined-builtin
7881 format : str ,
@@ -220,10 +223,62 @@ def register_schema( # pylint:disable=arguments-differ
220223 return SchemaProperties (** properties )
221224
222225 @overload
223- def get_schema (self , schema_id : str , ** kwargs : Any ) -> Schema : ...
226+ def get_schema (self , schema_id : str , ** kwargs : Any ) -> Schema :
227+ """Gets a registered schema.
228+
229+ To get a registered schema by its unique ID, pass the `schema_id` parameter and any optional
230+ keyword arguments. Azure Schema Registry guarantees that ID is unique within a namespace.
231+
232+ WARNING: If retrieving a schema format that is unsupported by this client version, upgrade to a client
233+ version that supports the schema format. Otherwise, the content MIME type string will be returned as
234+ the `format` value in the `properties` of the returned Schema.
235+
236+ :param str schema_id: References specific schema in registry namespace. Required if `group_name`,
237+ `name`, and `version` are not provided.
238+ :return: The schema stored in the registry associated with the provided arguments.
239+ :rtype: ~azure.schemaregistry.Schema
240+ :raises: :class:`~azure.core.exceptions.HttpResponseError`
241+
242+ .. admonition:: Example:
243+
244+ .. literalinclude:: ../samples/sync_samples/sample_code_schemaregistry.py
245+ :start-after: [START get_schema_sync]
246+ :end-before: [END get_schema_sync]
247+ :language: python
248+ :dedent: 4
249+ :caption: Get schema by id.
250+
251+ """
252+ ...
224253
225254 @overload
226- def get_schema (self , * , group_name : str , name : str , version : int , ** kwargs : Any ) -> Schema : ...
255+ def get_schema (self , * , group_name : str , name : str , version : int , ** kwargs : Any ) -> Schema :
256+ """Gets a registered schema.
257+
258+ To get a specific version of a schema within the specified schema group, pass in the required
259+ keyword arguments `group_name`, `name`, and `version` and any optional keyword arguments.
260+
261+ WARNING: If retrieving a schema format that is unsupported by this client version, upgrade to a client
262+ version that supports the schema format. Otherwise, the content MIME type string will be returned as
263+ the `format` value in the `properties` of the returned Schema.
264+
265+ :keyword str group_name: Name of schema group that contains the registered schema.
266+ :keyword str name: Name of schema which should be retrieved.
267+ :keyword int version: Version of schema which should be retrieved.
268+ :return: The schema stored in the registry associated with the provided arguments.
269+ :rtype: ~azure.schemaregistry.Schema
270+ :raises: :class:`~azure.core.exceptions.HttpResponseError`
271+
272+ .. admonition:: Example:
273+
274+ .. literalinclude:: ../samples/sync_samples/sample_code_schemaregistry.py
275+ :start-after: [START get_schema_by_version_sync]
276+ :end-before: [END get_schema_by_version_sync]
277+ :language: python
278+ :dedent: 4
279+ :caption: Get schema by version.
280+ """
281+ ...
227282
228283 @distributed_trace
229284 def get_schema ( # pylint: disable=docstring-missing-param,docstring-should-be-keyword
@@ -237,6 +292,10 @@ def get_schema( # pylint: disable=docstring-missing-param,docstring-should-be-k
237292 2) To get a specific version of a schema within the specified schema group, pass in the required
238293 keyword arguments `group_name`, `name`, and `version` and any optional keyword arguments.
239294
295+ WARNING: If retrieving a schema format that is unsupported by this client version, upgrade to a client
296+ version that supports the schema format. Otherwise, the content MIME type string will be returned as
297+ the `format` value in the `properties` of the returned Schema.
298+
240299 :param str schema_id: References specific schema in registry namespace. Required if `group_name`,
241300 `name`, and `version` are not provided.
242301 :keyword str group_name: Name of schema group that contains the registered schema.
@@ -281,8 +340,8 @@ def get_schema( # pylint: disable=docstring-missing-param,docstring-should-be-k
281340 id = schema_id ,
282341 cls = prepare_schema_result ,
283342 headers = { # TODO: remove when multiple content types in response are supported
284- "Accept" : """application/json; serialization=Avro, application/json; \
285- serialization=json, text/plain; charset=utf-8"""
343+ "Accept" : """application/json; serialization=Avro, application/json; """
344+ """ serialization=json, text/plain; charset=utf-8"""
286345 },
287346 stream = True ,
288347 ** http_request_kwargs ,
@@ -305,8 +364,8 @@ def get_schema( # pylint: disable=docstring-missing-param,docstring-should-be-k
305364 schema_version = version ,
306365 cls = prepare_schema_result ,
307366 headers = { # TODO: remove when multiple content types in response are supported
308- "Accept" : """application/json; serialization=Avro, application/json; \
309- serialization=json, text/plain; charset=utf-8"""
367+ "Accept" : """application/json; serialization=Avro, application/json; """
368+ """ serialization=json, text/plain; charset=utf-8"""
310369 },
311370 stream = True ,
312371 ** http_request_kwargs ,
@@ -414,6 +473,16 @@ def __init__(self, **kwargs: Any) -> None:
414473 def __repr__ (self ) -> str :
415474 return f"Schema(definition={ self .definition } , properties={ self .properties } )" [:1024 ]
416475
476+ # ApiVersion was added to a previously GA'd version. However, newer libraries should not
477+ # accept ApiVersion enums and only take strings. Leaving this here for backwards compatibility.
478+ class ApiVersion (str , Enum , metaclass = CaseInsensitiveEnumMeta ):
479+ """
480+ Represents the Schema Registry API version to use for requests.
481+ """
482+
483+ V2021_10 = "2021-10"
484+ V2022_10 = "2022-10"
485+ """This is the default version."""
417486
418487###### Encoder Protocols ######
419488
0 commit comments