diff --git a/karapace/schema_models.py b/karapace/schema_models.py index 43218a5c2..58ab20835 100644 --- a/karapace/schema_models.py +++ b/karapace/schema_models.py @@ -188,15 +188,16 @@ def __init__(self, schema_str: str, dependencies: Mapping[str, Dependency] | Non self.schema_str = json_encode(json_decode(schema_str), compact=True, sort_keys=True) self.dependencies = dependencies self.unique_id = 0 + self.regex = re.compile(r"^\s*\[") def union_safe_schema_str(self, schema_str: str) -> str: # in case we meet union - we use it as is - regex = re.compile(r"^\s*\[") + base_schema = ( f'{{"name": "___RESERVED_KARAPACE_WRAPPER_NAME_{self.unique_id}___",' f'"type": "record", "fields": [{{"name": "name", "type":' ) - if regex.match(schema_str): + if self.regex.match(schema_str): return f"{base_schema} {schema_str}}}]}}" return f"{base_schema} [{schema_str}]}}]}}" @@ -229,7 +230,6 @@ def parse( references: Sequence[Reference] | None = None, dependencies: Mapping[str, Dependency] | None = None, normalize: bool = False, - dependencies_compat: bool = False, ) -> ParsedTypedSchema: if schema_type not in [SchemaType.AVRO, SchemaType.JSONSCHEMA, SchemaType.PROTOBUF]: raise InvalidSchema(f"Unknown parser {schema_type} for {schema_str}") @@ -237,7 +237,7 @@ def parse( parsed_schema: Draft7Validator | AvroSchema | ProtobufSchema if schema_type is SchemaType.AVRO: try: - if dependencies or dependencies_compat: + if dependencies: wrapped_schema_str = AvroMerge(schema_str, dependencies).wrap() else: wrapped_schema_str = schema_str @@ -246,7 +246,7 @@ def parse( validate_enum_symbols=validate_avro_enum_symbols, validate_names=validate_avro_names, ) - if dependencies or dependencies_compat: + if dependencies: if isinstance(parsed_schema, avro.schema.UnionSchema): parsed_schema_result = parsed_schema.schemas[-1].fields[0].type.schemas[-1] diff --git a/tests/integration/test_schema_avro_references.py b/tests/integration/test_schema_avro_references.py index 3c4cfc8ba..b1308e0e8 100644 --- a/tests/integration/test_schema_avro_references.py +++ b/tests/integration/test_schema_avro_references.py @@ -54,7 +54,7 @@ ], } -SCHEMA_PERSON_INT_LONG = { +SCHEMA_PERSON_AGE_INT_LONG = { "type": "record", "name": "Person", "namespace": "com.netapp", @@ -66,7 +66,7 @@ ], } -SCHEMA_PERSON_INT_STRING = { +SCHEMA_PERSON_AGE_LONG_STRING = { "type": "record", "name": "Person", "namespace": "com.netapp", @@ -232,7 +232,7 @@ async def test_avro_references_compatibility(registry_async_client: Client) -> N f"compatibility/subjects/{subject_prefix}person/versions/latest", json={ "schemaType": "AVRO", - "schema": json.dumps(SCHEMA_PERSON_INT_LONG), + "schema": json.dumps(SCHEMA_PERSON_AGE_INT_LONG), "references": person_references(subject_prefix), }, ) @@ -242,7 +242,7 @@ async def test_avro_references_compatibility(registry_async_client: Client) -> N f"compatibility/subjects/{subject_prefix}person/versions/latest", json={ "schemaType": "AVRO", - "schema": json.dumps(SCHEMA_PERSON_INT_STRING), + "schema": json.dumps(SCHEMA_PERSON_AGE_LONG_STRING), "references": person_references(subject_prefix), }, )