Skip to content

Commit da670e3

Browse files
authored
Merge pull request #468 from aiven/jjaakola-aiven-fix-schema-listing-endpoint
fix: schema list endpoint to iterate subject schemas
2 parents 66d330b + ec94b86 commit da670e3

2 files changed

Lines changed: 39 additions & 10 deletions

File tree

karapace/schema_registry_apis.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,20 @@ async def schemas_list(self, content_type: str, *, request: HTTPRequest, user: O
362362

363363
schemas = await self.schema_registry.schemas_list(include_deleted=deleted, latest_only=latest_only)
364364
response_schemas = []
365-
for subject, schema in schemas.items():
365+
for subject, schema_data in schemas.items():
366366
if self._auth and not self._auth.check_authorization(user, Operation.Read, f"Subject:{subject}"):
367367
continue
368-
response_schemas.append(
369-
{
370-
"subject": subject,
371-
"version": schema["version"],
372-
"id": schema["id"],
373-
"schemaType": schema.get("schemaType", "AVRO"),
374-
"schema": schema["schema"].schema_str,
375-
}
376-
)
368+
for schema in schema_data:
369+
response_schemas.append(
370+
{
371+
"subject": subject,
372+
"version": schema["version"],
373+
"id": schema["id"],
374+
"schemaType": schema.get("schemaType", "AVRO"),
375+
"schema": schema["schema"].schema_str,
376+
}
377+
)
378+
377379
self.r(
378380
body=response_schemas,
379381
content_type=content_type,

tests/integration/test_schema.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,33 @@ async def test_schema_types(registry_async_client: Client, trail: str) -> None:
12551255
assert "PROTOBUF" in json_res
12561256

12571257

1258+
@pytest.mark.parametrize("trail", ["", "/"])
1259+
async def test_schema_list_endpoint(registry_async_client: Client, trail: str) -> None:
1260+
"""Test schema endpoint list"""
1261+
subject = create_subject_name_factory(f"test_schema_subject_list_endpoint-{trail}")()
1262+
unique_field_factory = create_field_name_factory(trail)
1263+
1264+
unique = unique_field_factory()
1265+
schema_str = json.dumps({"type": "string", "unique": unique})
1266+
res = await registry_async_client.post(
1267+
f"subjects/{subject}/versions{trail}",
1268+
json={"schema": schema_str},
1269+
)
1270+
assert res.status_code == 200
1271+
assert "id" in res.json()
1272+
schema_id = res.json()["id"]
1273+
1274+
res = await registry_async_client.get("schemas")
1275+
assert res.status_code == 200
1276+
result_json = res.json()
1277+
assert len(result_json) == 1
1278+
schema_data = result_json[0]
1279+
assert schema_data.get("id") == schema_id
1280+
assert schema_data.get("subject") == subject
1281+
assert schema_data.get("version") == 1
1282+
assert schema_data.get("schema") == schema_str
1283+
1284+
12581285
@pytest.mark.parametrize("trail", ["", "/"])
12591286
async def test_schema_repost(registry_async_client: Client, trail: str) -> None:
12601287
""" "

0 commit comments

Comments
 (0)