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

[CORE-3182] Feat/core 3182/schema registry json external references #23677

Draft
wants to merge 10 commits into
base: dev
Choose a base branch
from
Draft
1 change: 1 addition & 0 deletions src/v/pandaproxy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ redpanda_cc_library(
"schema_registry/sharded_store.cc",
"schema_registry/types.cc",
"schema_registry/validation.cc",
"schema_registry/util.cc",
"server.cc",
],
hdrs = [
Expand Down
1 change: 1 addition & 0 deletions src/v/pandaproxy/schema_registry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ v_cc_library(
json.cc
protobuf.cc
validation.cc
util.cc
${schema_registry_file}
DEPS
v::pandaproxy_common
Expand Down
44 changes: 1 addition & 43 deletions src/v/pandaproxy/schema_registry/avro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "pandaproxy/schema_registry/errors.h"
#include "pandaproxy/schema_registry/sharded_store.h"
#include "pandaproxy/schema_registry/types.h"
#include "pandaproxy/schema_registry/util.h"
#include "strings/string_switch.h"

#include <seastar/core/coroutine.hh>
Expand Down Expand Up @@ -517,49 +518,6 @@ ss::sstring avro_schema_definition::name() const {
return _impl.root()->name().fullname();
};

class collected_schema {
public:
bool contains(const ss::sstring& name) const {
return _names.contains(name);
}
bool insert(ss::sstring name, canonical_schema_definition def) {
bool inserted = _names.insert(std::move(name)).second;
if (inserted) {
_schemas.push_back(std::move(def).raw());
}
return inserted;
}
canonical_schema_definition::raw_string flatten() && {
iobuf out;
for (auto& s : _schemas) {
out.append(std::move(s));
out.append("\n", 1);
}
return canonical_schema_definition::raw_string{std::move(out)};
}

private:
absl::flat_hash_set<ss::sstring> _names;
std::vector<canonical_schema_definition::raw_string> _schemas;
};

ss::future<collected_schema> collect_schema(
sharded_store& store,
collected_schema collected,
ss::sstring name,
canonical_schema schema) {
for (const auto& ref : schema.def().refs()) {
if (!collected.contains(ref.name)) {
auto ss = co_await store.get_subject_schema(
ref.sub, ref.version, include_deleted::no);
collected = co_await collect_schema(
store, std::move(collected), ref.name, std::move(ss.schema));
}
}
collected.insert(std::move(name), std::move(schema).def());
co_return std::move(collected);
}

ss::future<avro_schema_definition>
make_avro_schema_definition(sharded_store& store, canonical_schema schema) {
std::optional<avro::Exception> ex;
Expand Down
Loading