Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# --------------------------------------------------------------------------
from typing import Any, TYPE_CHECKING, Union

from ._utils import get_http_request_kwargs
from ._common._constants import SchemaFormat
from ._common._schema import Schema, SchemaProperties
from ._common._response_handlers import (
Expand Down Expand Up @@ -114,16 +115,17 @@ def register_schema(
except AttributeError:
pass

http_request_kwargs = get_http_request_kwargs(kwargs)
request = schema_rest.build_register_request(
group_name=group_name,
schema_name=name,
content=schema_definition,
serialization_type=format,
content_type=kwargs.pop("content_type", "application/json"),
**kwargs
**http_request_kwargs
)

response = self._generated_client.send_request(request)
response = self._generated_client.send_request(request, **kwargs)
response.raise_for_status()
return _parse_response_schema_properties(response)

Expand All @@ -147,7 +149,8 @@ def get_schema(self, id, **kwargs): # pylint:disable=redefined-builtin
:caption: Get schema by id.

"""
request = schema_rest.build_get_by_id_request(schema_id=id)
http_request_kwargs = get_http_request_kwargs(kwargs)
request = schema_rest.build_get_by_id_request(schema_id=id, **http_request_kwargs)
response = self._generated_client.send_request(request, **kwargs)
response.raise_for_status()
return _parse_response_schema(response)
Expand Down Expand Up @@ -183,13 +186,14 @@ def get_schema_properties(
except AttributeError:
pass

http_request_kwargs = get_http_request_kwargs(kwargs)
request = schema_rest.build_query_id_by_content_request(
group_name=group_name,
schema_name=name,
content=schema_definition,
serialization_type=format,
content_type=kwargs.pop("content_type", "application/json"),
**kwargs
**http_request_kwargs
)

response = self._generated_client.send_request(request, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

def get_http_request_kwargs(kwargs):
http_request_keywords = ["params", "headers", "json", "data", "files"]
http_request_kwargs = {key: kwargs.pop(key, None) for key in http_request_keywords if key in kwargs}
return http_request_kwargs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# --------------------------------------------------------------------------
from typing import Any, TYPE_CHECKING, Union

from .._utils import get_http_request_kwargs
from .._common._constants import SchemaFormat
from .._common._schema import Schema, SchemaProperties
from .._common._response_handlers import (
Expand Down Expand Up @@ -116,16 +117,17 @@ async def register_schema(
except AttributeError:
pass

http_request_kwargs = get_http_request_kwargs(kwargs)
request = schema_rest.build_register_request(
group_name=group_name,
schema_name=name,
content=schema_definition,
serialization_type=format,
content_type=kwargs.pop("content_type", "application/json"),
**kwargs
**http_request_kwargs
)

response = await self._generated_client.send_request(request)
response = await self._generated_client.send_request(request, **kwargs)
response.raise_for_status()
return _parse_response_schema_properties(response)

Expand All @@ -152,7 +154,8 @@ async def get_schema(
:caption: Get schema by id.

"""
request = schema_rest.build_get_by_id_request(schema_id=id)
http_request_kwargs = get_http_request_kwargs(kwargs)
request = schema_rest.build_get_by_id_request(schema_id=id, **http_request_kwargs)
response = await self._generated_client.send_request(request, **kwargs)
response.raise_for_status()
return _parse_response_schema(response)
Expand Down Expand Up @@ -192,13 +195,14 @@ async def get_schema_properties(
except AttributeError:
pass

http_request_kwargs = get_http_request_kwargs(kwargs)
request = schema_rest.build_query_id_by_content_request(
group_name=group_name,
schema_name=name,
content=schema_definition,
serialization_type=format,
content_type=kwargs.pop("content_type", "application/json"),
**kwargs
**http_request_kwargs
)

response = await self._generated_client.send_request(request, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ async def test_schema_basic_async(self, schemaregistry_fully_qualified_namespace
schema_name = self.get_resource_name('test-schema-basic-async')
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
format = "Avro"
schema_properties = await client.register_schema(schemaregistry_group, schema_name, schema_str, format)
schema_properties = await client.register_schema(schemaregistry_group, schema_name, schema_str, format, logging_enable=True)

assert schema_properties.id is not None
assert schema_properties.version is 1
assert schema_properties.format == "Avro"

returned_schema = await client.get_schema(id=schema_properties.id)
returned_schema = await client.get_schema(id=schema_properties.id, logging_enable=True)

assert returned_schema.properties.id == schema_properties.id
assert returned_schema.properties.version == 1
assert returned_schema.properties.format == "Avro"
assert returned_schema.schema_definition == schema_str

returned_schema_properties = await client.get_schema_properties(schemaregistry_group, schema_name, schema_str, format)
returned_schema_properties = await client.get_schema_properties(schemaregistry_group, schema_name, schema_str, format, logging_enable=True)

assert returned_schema_properties.id == schema_properties.id
assert returned_schema_properties.version == 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ def test_schema_basic(self, schemaregistry_fully_qualified_namespace, schemaregi
schema_name = self.get_resource_name('test-schema-basic')
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
format = "Avro"
schema_properties = client.register_schema(schemaregistry_group, schema_name, schema_str, format)
schema_properties = client.register_schema(schemaregistry_group, schema_name, schema_str, format, logging_enable=True)

assert schema_properties.id is not None
assert schema_properties.version is 1
assert schema_properties.format == "Avro"

returned_schema = client.get_schema(id=schema_properties.id)
returned_schema = client.get_schema(id=schema_properties.id, logging_enable=True)

assert returned_schema.properties.id == schema_properties.id
assert returned_schema.properties.version == 1
assert returned_schema.properties.format == "Avro"
assert returned_schema.schema_definition == schema_str

returned_schema_properties = client.get_schema_properties(schemaregistry_group, schema_name, schema_str, format)
returned_schema_properties = client.get_schema_properties(schemaregistry_group, schema_name, schema_str, format, logging_enable=True)

assert returned_schema_properties.id == schema_properties.id
assert returned_schema_properties.version == 1
Expand Down