From a4082029c3463992a2b7a40d6820ca004da64019 Mon Sep 17 00:00:00 2001 From: Ben Pope Date: Mon, 5 Jun 2023 22:26:25 +0100 Subject: [PATCH] schema_registry/store: get_schema now returns references `GET /schemas/ids/` now returns its references. Fixes #11194 Signed-off-by: Ben Pope --- .../schema_registry/requests/get_schemas_ids_id.h | 15 +++++++++++++++ .../schema_registry/test/sharded_store.cc | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/src/v/pandaproxy/schema_registry/requests/get_schemas_ids_id.h b/src/v/pandaproxy/schema_registry/requests/get_schemas_ids_id.h index 04a5a083ed424..6eec85d6a497f 100644 --- a/src/v/pandaproxy/schema_registry/requests/get_schemas_ids_id.h +++ b/src/v/pandaproxy/schema_registry/requests/get_schemas_ids_id.h @@ -30,6 +30,21 @@ inline void rjson_serialize( } w.Key("schema"); ::json::rjson_serialize(w, res.definition.raw()); + if (!res.definition.refs().empty()) { + w.Key("references"); + w.StartArray(); + for (const auto& ref : res.definition.refs()) { + w.StartObject(); + w.Key("name"); + ::json::rjson_serialize(w, ref.name); + w.Key("subject"); + ::json::rjson_serialize(w, ref.sub); + w.Key("version"); + ::json::rjson_serialize(w, ref.version); + w.EndObject(); + } + w.EndArray(); + } w.EndObject(); } diff --git a/src/v/pandaproxy/schema_registry/test/sharded_store.cc b/src/v/pandaproxy/schema_registry/test/sharded_store.cc index 0687ee3f3bdf6..2c2dbc7a67c2f 100644 --- a/src/v/pandaproxy/schema_registry/test/sharded_store.cc +++ b/src/v/pandaproxy/schema_registry/test/sharded_store.cc @@ -67,6 +67,13 @@ SEASTAR_THREAD_TEST_CASE(test_sharded_store_referenced_by) { store.is_referenced(pps::subject{"simple.proto"}, pps::schema_version{1}) .get()); + auto importing = store.get_schema_definition(pps::schema_id{2}).get(); + BOOST_REQUIRE_EQUAL(importing.refs().size(), 1); + BOOST_REQUIRE_EQUAL(importing.refs()[0].sub, imported.refs()[0].sub); + BOOST_REQUIRE_EQUAL( + importing.refs()[0].version, imported.refs()[0].version); + BOOST_REQUIRE_EQUAL(importing.refs()[0].name, imported.refs()[0].name); + // soft delete subject store .upsert(