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

rest api integrate jsonschema compatibility #175

Merged
merged 2 commits into from
Mar 17, 2021

Conversation

hackaugusto
Copy link
Contributor

@hackaugusto hackaugusto commented Mar 12, 2021

Depends on #171 merged.

This integrates the jsonschema compatibility check with the existing rest apis.

@hackaugusto hackaugusto force-pushed the hacka-rest-api-integrate-jsonschema-compatibility branch 2 times, most recently from 3fb0e2b to 8fb3604 Compare March 12, 2021 12:19
@hackaugusto hackaugusto marked this pull request as ready for review March 12, 2021 13:11
@hackaugusto hackaugusto mentioned this pull request Mar 12, 2021
5 tasks
@hackaugusto hackaugusto force-pushed the hacka-rest-api-integrate-jsonschema-compatibility branch 4 times, most recently from ce49fb9 to 65dddde Compare March 12, 2021 16:06
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
Copy link
Contributor

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

@hackaugusto hackaugusto force-pushed the hacka-rest-api-integrate-jsonschema-compatibility branch from 27b217c to cbcf6bd Compare March 16, 2021 11:40
@hackaugusto hackaugusto force-pushed the hacka-rest-api-integrate-jsonschema-compatibility branch from cbcf6bd to 569eb1f Compare March 16, 2021 14:12
karapace/avro_compatibility.py Show resolved Hide resolved

def check_compatibility(
source: TypedSchema, target: TypedSchema, compatibility_mode: CompatibilityModes
) -> SchemaCompatibilityResult:
Copy link
Contributor Author

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:
Copy link
Contributor Author

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

tests/integration/conftest.py Outdated Show resolved Hide resolved
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:
Copy link
Contributor Author

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.
@hackaugusto hackaugusto force-pushed the hacka-rest-api-integrate-jsonschema-compatibility branch from 569eb1f to 44f0c0b Compare March 16, 2021 14:27
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"
Copy link
Contributor Author

@hackaugusto hackaugusto Mar 16, 2021

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)

@HelenMel
Copy link
Contributor

HelenMel commented Mar 16, 2021

LGTM. Do you have an intent to add something more?

@hackaugusto
Copy link
Contributor Author

LGTM. Do you have an intent to add something more?

Nope

@HelenMel HelenMel merged commit 61b700e into master Mar 17, 2021
@HelenMel HelenMel deleted the hacka-rest-api-integrate-jsonschema-compatibility branch March 17, 2021 07:35
@swarmia
Copy link

swarmia bot commented Mar 17, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants