-
Notifications
You must be signed in to change notification settings - Fork 73
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
rest api integrate jsonschema compatibility #175
rest api integrate jsonschema compatibility #175
Conversation
3fb0e2b
to
8fb3604
Compare
ce49fb9
to
65dddde
Compare
karapace/avro_compatibility.py
Outdated
from enum import Enum | ||
from typing import Any, cast, Dict, List, Optional, Set | ||
from enum import Enum, unique | ||
from typing import Any, cast, Dict, Generic, List, Optional, Set, TypeVar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm....Generics...things become interesting
27b217c
to
cbcf6bd
Compare
cbcf6bd
to
569eb1f
Compare
|
||
def check_compatibility( | ||
source: TypedSchema, target: TypedSchema, compatibility_mode: CompatibilityModes | ||
) -> SchemaCompatibilityResult: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of raising, now the error is returned. This allows the API to report the error message.
import json | ||
|
||
|
||
def parse_schema_definition(schema_definition: str) -> Draft7Validator: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to move the function to avoid circular imports
result = check_avro_compatibility(reader_schema=target.schema, writer_schema=source.schema) | ||
result = result.merged_with(check_avro_compatibility(reader_schema=source.schema, writer_schema=target.schema)) | ||
|
||
elif source.schema_type is SchemaType.JSONSCHEMA: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this is pretty much all that was needed to support jsonschema in the APIs, the rest of the code was already in place.
This changes the code to use the SchemaCompatibilityResult class instead of IncompatibleSchema exception to report the compatibility status, this allows the server to use the incompatibility message on the response, which can be useful for understading what caused the compatibility problem.
569eb1f
to
44f0c0b
Compare
subschema = schema.get(type_.value) | ||
if subschema is not None: | ||
# https://json-schema.org/draft/2020-12/json-schema-core.html#rfc.section.10.2.1 | ||
assert isinstance(subschema, list), "allOf/anyOf/oneOf must be an array" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was caught by mypy, not by a test.
I had to add the isinstance
check to narrow the type, however that assert fails for NOT
, so the two cases had to be split and it fixed the bug with not
(I probably need to also add a unit test for that)
LGTM. Do you have an intent to add something more? |
Nope |
Depends on #171merged.This integrates the jsonschema compatibility check with the existing rest apis.