Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ single_version_override(

bazel_dep(name = "rules_shell", version = "0.4.1", dev_dependency = True)

bazel_dep(name = "protovalidate", version = "1.0.0")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but it's a fairly heavy dependency to only need the protos :)

I think it's fine tho don't bother changing it


python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True)
python.toolchain(
ignore_root_user_error = True,
Expand Down
79 changes: 78 additions & 1 deletion MODULE.bazel.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/v/pandaproxy/schema_registry/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ redpanda_cc_library(
"@protobuf//src/google/protobuf/compiler:importer",
"@protobuf//src/google/protobuf/io",
"@protobuf//src/google/protobuf/io:tokenizer",
"@protovalidate//proto/protovalidate/buf/validate:validate_proto_cc",
"@rapidjson",
"@re2",
] + well_known_cc_protos,
Expand Down
5 changes: 4 additions & 1 deletion src/v/pandaproxy/schema_registry/protobuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <boost/algorithm/string/trim.hpp>
#include <boost/range/combine.hpp>
#include <buf/validate/validate.pb.h>
#include <confluent/meta.pb.h>
#include <confluent/types/decimal.pb.h>
#include <fmt/core.h>
Expand Down Expand Up @@ -148,7 +149,9 @@ static const known_types_set known_types{
google::protobuf::FieldMask::GetDescriptor()->file(),
google::protobuf::Struct::GetDescriptor()->file(),
google::protobuf::Timestamp::GetDescriptor()->file(),
google::protobuf::FieldDescriptorProto::GetDescriptor()->file()};
google::protobuf::FieldDescriptorProto::GetDescriptor()->file(),
buf::validate::Rule::GetDescriptor()->file(),
};

class io_error_collector final : public pb::io::ErrorCollector {
enum class level {
Expand Down
10 changes: 10 additions & 0 deletions src/v/pandaproxy/schema_registry/test/compatibility_protobuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ import "google/type/quaternion.proto";
import "google/type/timeofday.proto";
import "confluent/meta.proto";
import "confluent/types/decimal.proto";
import "buf/validate/validate.proto";

message well_known_types {
google.protobuf.Any any = 1;
Expand Down Expand Up @@ -345,6 +346,15 @@ message well_known_types {
google.type.TimeOfDay time_of_day = 46;
confluent.Meta c_meta = 47;
confluent.type.Decimal c_decimal = 48;
buf.validate.FieldRules field_rules = 49;
buf.validate.StringRules string_rules = 50;
buf.validate.Int32Rules int32_rules = 51;
buf.validate.MessageRules message_rules = 52;
buf.validate.RepeatedRules repeated_rules = 53;
buf.validate.MapRules map_rules = 54;
buf.validate.AnyRules any_rules = 55;
buf.validate.DurationRules duration_rules = 56;
buf.validate.TimestampRules timestamp_rules = 57;
})",
pps::schema_type::protobuf}};
store.insert(schema.share(), pps::schema_version{1});
Expand Down
22 changes: 22 additions & 0 deletions tests/rptest/tests/schema_registry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ def get_subject_name(sns: str, topic: str, field: MessageField, record_name: str
google.protobuf.Timestamp timestamp = 1;
}"""

validate_proto_def = """
syntax = "proto3";

import "buf/validate/validate.proto";

message TestValidate {
buf.validate.FieldRules field_rules = 1;
buf.validate.StringRules string_rules = 2;
buf.validate.Int32Rules int32_rules = 3;
buf.validate.MessageRules message_rules = 4;
buf.validate.TimestampRules timestamp_rules = 5;
}"""
Comment on lines +297 to +303
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a more realistic test if you use them as annotations like they are supposed to be :)


json_number_schema_def = '{"type":"number"}'

validation_schemas = dict(
Expand Down Expand Up @@ -6773,6 +6786,12 @@ def test_references(self):
result = self.sr_client.register_schema(well_known_subject, well_known_schema)
assert result == 3, f"Result: {result}"

validate_subject = "topic_4-key"
validate_schema = Schema(validate_proto_def, "PROTOBUF")

result = self.sr_client.register_schema(validate_subject, validate_schema)
assert result == 4, f"Result: {result}"

result = self.sr_client.get_schema(1)
assert result == simple_schema, f"Result: {result}"

Expand All @@ -6782,6 +6801,9 @@ def test_references(self):
result = self.sr_client.get_schema(3)
assert result == well_known_schema, f"Result: {result}"

result = self.sr_client.get_schema(4)
assert result == validate_schema, f"Result: {result}"


# dataset for SchemaRegistryCompatibilityModes: schemas is a list of 3 schemas compatible for `mode`, `antimode` is a suitable mode that will make the compat check for schemas fail
CompatDataset = NamedTuple(
Expand Down