Skip to content

Commit

Permalink
fixup PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
libretto committed Sep 26, 2024
1 parent 653561e commit bf82f81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions karapace/schema_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}]}}]}}"

Expand Down Expand Up @@ -229,15 +230,14 @@ 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}")
parsed_schema_result: Draft7Validator | AvroSchema | ProtobufSchema
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
Expand All @@ -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]

Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_schema_avro_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
],
}

SCHEMA_PERSON_INT_LONG = {
SCHEMA_PERSON_AGE_INT_LONG = {
"type": "record",
"name": "Person",
"namespace": "com.netapp",
Expand All @@ -66,7 +66,7 @@
],
}

SCHEMA_PERSON_INT_STRING = {
SCHEMA_PERSON_AGE_LONG_STRING = {
"type": "record",
"name": "Person",
"namespace": "com.netapp",
Expand Down Expand Up @@ -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),
},
)
Expand All @@ -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),
},
)
Expand Down

0 comments on commit bf82f81

Please sign in to comment.