Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: schema error codes required to be json serializable #1010

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
4 changes: 2 additions & 2 deletions src/schema_registry/routers/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
See LICENSE for details
"""

from enum import Enum, unique
from enum import Enum, IntEnum, unique
from fastapi import HTTPException, status
from fastapi.exceptions import RequestValidationError


@unique
class SchemaErrorCodes(Enum):
class SchemaErrorCodes(IntEnum):
HTTP_BAD_REQUEST = status.HTTP_400_BAD_REQUEST
HTTP_NOT_FOUND = status.HTTP_404_NOT_FOUND
HTTP_CONFLICT = status.HTTP_409_CONFLICT
Expand Down
6 changes: 2 additions & 4 deletions tests/e2e/schema_registry/test_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,12 @@ async def not_schemas_are_backward_compatible(
)


@pytest.mark.parametrize("trail", ["", "/"])
@pytest.mark.parametrize("compatibility", [CompatibilityModes.FORWARD, CompatibilityModes.BACKWARD, CompatibilityModes.FULL])
@pytest.mark.parametrize("metadata", [None, {}])
@pytest.mark.parametrize("rule_set", [None, {}])
async def test_same_jsonschema_must_have_same_id(
registry_async_client: Client,
compatibility: CompatibilityModes,
trail: str,
metadata: SchemaMetadata,
rule_set: SchemaRuleSet,
) -> None:
Expand All @@ -251,7 +249,7 @@ async def test_same_jsonschema_must_have_same_id(
assert res.status_code == 200

first_res = await registry_async_client.post(
f"subjects/{subject}/versions{trail}",
f"subjects/{subject}/versions",
json={
"schema": json.dumps(schema.schema),
"schemaType": SchemaType.JSONSCHEMA.value,
Expand All @@ -264,7 +262,7 @@ async def test_same_jsonschema_must_have_same_id(
assert first_id

second_res = await registry_async_client.post(
f"subjects/{subject}/versions{trail}",
f"subjects/{subject}/versions",
json={
"schema": json.dumps(schema.schema),
"schemaType": SchemaType.JSONSCHEMA.value,
Expand Down
31 changes: 13 additions & 18 deletions tests/integration/test_schema_protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ def add_slashes(text: str) -> str:

# This test ProtoBuf schemas in subject registeration, compatibility of evolved version and querying the schema
# w.r.t. normalization of whitespace and other minor differences to verify equality and inequality comparison of such schemas
@pytest.mark.parametrize("trail", ["", "/"])
@pytest.mark.parametrize("registry_cluster", [{"config": {}}, {"config": {"use_protobuf_formatter": True}}], indirect=True)
async def test_protobuf_schema_normalization(registry_async_client: Client, trail: str) -> None:
subject = create_subject_name_factory(f"test_protobuf_schema_compatibility-{trail}")()
async def test_protobuf_schema_normalization(registry_async_client: Client) -> None:
subject = create_subject_name_factory("test_protobuf_schema_compatibility")()

res = await registry_async_client.put(f"config/{subject}{trail}", json={"compatibility": "BACKWARD"})
res = await registry_async_client.put(f"config/{subject}", json={"compatibility": "BACKWARD"})
assert res.status_code == 200

original_schema = """
Expand Down Expand Up @@ -91,36 +90,34 @@ async def test_protobuf_schema_normalization(registry_async_client: Client, trai
)

res = await registry_async_client.post(
f"subjects/{subject}/versions{trail}", json={"schemaType": "PROTOBUF", "schema": original_schema}
f"subjects/{subject}/versions", json={"schemaType": "PROTOBUF", "schema": original_schema}
)
assert res.status_code == 200
assert "id" in res.json()
original_id = res.json()["id"]

res = await registry_async_client.post(
f"subjects/{subject}/versions{trail}", json={"schemaType": "PROTOBUF", "schema": original_schema}
f"subjects/{subject}/versions", json={"schemaType": "PROTOBUF", "schema": original_schema}
)
assert res.status_code == 200
assert "id" in res.json()
assert original_id == res.json()["id"], "No duplication"

res = await registry_async_client.post(
f"subjects/{subject}/versions{trail}", json={"schemaType": "PROTOBUF", "schema": original_schema_with_whitespace}
f"subjects/{subject}/versions", json={"schemaType": "PROTOBUF", "schema": original_schema_with_whitespace}
)
assert res.status_code == 200
assert "id" in res.json()
assert original_id == res.json()["id"], "No duplication with whitespace differences"

res = await registry_async_client.post(
f"subjects/{subject}{trail}", json={"schemaType": "PROTOBUF", "schema": original_schema}
)
res = await registry_async_client.post(f"subjects/{subject}", json={"schemaType": "PROTOBUF", "schema": original_schema})
assert res.status_code == 200
assert "id" in res.json()
assert "schema" in res.json()
assert original_id == res.json()["id"], "Check returns original id"

res = await registry_async_client.post(
f"subjects/{subject}{trail}", json={"schemaType": "PROTOBUF", "schema": original_schema_with_whitespace}
f"subjects/{subject}", json={"schemaType": "PROTOBUF", "schema": original_schema_with_whitespace}
)
assert res.status_code == 200
assert "id" in res.json()
Expand All @@ -146,36 +143,34 @@ async def test_protobuf_schema_normalization(registry_async_client: Client, trai
evolved_schema = trim_margin(evolved_schema)

res = await registry_async_client.post(
f"compatibility/subjects/{subject}/versions/latest{trail}",
f"compatibility/subjects/{subject}/versions/latest",
json={"schemaType": "PROTOBUF", "schema": evolved_schema},
)
assert res.status_code == 200
assert res.json() == {"is_compatible": True}

res = await registry_async_client.post(
f"subjects/{subject}/versions{trail}", json={"schemaType": "PROTOBUF", "schema": evolved_schema}
f"subjects/{subject}/versions", json={"schemaType": "PROTOBUF", "schema": evolved_schema}
)
assert res.status_code == 200
assert "id" in res.json()
assert original_id != res.json()["id"], "Evolved is not equal"
evolved_id = res.json()["id"]

res = await registry_async_client.post(
f"compatibility/subjects/{subject}/versions/latest{trail}",
f"compatibility/subjects/{subject}/versions/latest",
json={"schemaType": "PROTOBUF", "schema": original_schema},
)
assert res.json() == {"is_compatible": True}
assert res.status_code == 200
res = await registry_async_client.post(
f"subjects/{subject}/versions{trail}", json={"schemaType": "PROTOBUF", "schema": original_schema}
f"subjects/{subject}/versions", json={"schemaType": "PROTOBUF", "schema": original_schema}
)
assert res.status_code == 200
assert "id" in res.json()
assert original_id == res.json()["id"], "Original id again"

res = await registry_async_client.post(
f"subjects/{subject}{trail}", json={"schemaType": "PROTOBUF", "schema": evolved_schema}
)
res = await registry_async_client.post(f"subjects/{subject}", json={"schemaType": "PROTOBUF", "schema": evolved_schema})
assert res.status_code == 200
assert "id" in res.json()
assert "schema" in res.json()
Expand Down
Loading