Skip to content

Commit

Permalink
schema_registry: Tolerate null metadata and ruleSet
Browse files Browse the repository at this point in the history
In the absence of supporting these features, it's friendly to tolerate
clients that explicitly set them to null, such as the latest DotNet
client.

Fixes redpanda-data#23038

Signed-off-by: Ben Pope <[email protected]>
  • Loading branch information
BenPope committed Aug 23, 2024
1 parent 5e3311a commit 55bd576
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/v/pandaproxy/schema_registry/requests/post_subject_versions.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class post_subject_versions_request_handler
schema,
id,
version,
metadata,
ruleset,
schema_type,
references,
reference,
Expand Down Expand Up @@ -74,6 +76,8 @@ class post_subject_versions_request_handler
.match("schema", state::schema)
.match("id", state::id)
.match("version", state::version)
.match("metadata", state::metadata)
.match("ruleSet", state::ruleset)
.match("schemaType", state::schema_type)
.match("references", state::references)
.default_match(std::nullopt)};
Expand All @@ -97,6 +101,8 @@ class post_subject_versions_request_handler
case state::schema:
case state::id:
case state::version:
case state::metadata:
case state::ruleset:
case state::schema_type:
case state::references:
case state::reference_name:
Expand All @@ -107,6 +113,28 @@ class post_subject_versions_request_handler
return false;
}

bool Null() {
switch (_state) {
case state::metadata:
case state::ruleset:
_state = state::record;
return true;
case state::empty:
case state::record:
case state::schema:
case state::id:
case state::version:
case state::schema_type:
case state::references:
case state::reference:
case state::reference_name:
case state::reference_subject:
case state::reference_version:
break;
}
return false;
}

bool Uint(int i) {
switch (_state) {
case state::id: {
Expand All @@ -127,6 +155,8 @@ class post_subject_versions_request_handler
case state::empty:
case state::record:
case state::schema:
case state::metadata:
case state::ruleset:
case state::schema_type:
case state::references:
case state::reference:
Expand Down Expand Up @@ -170,6 +200,8 @@ class post_subject_versions_request_handler
case state::record:
case state::id:
case state::version:
case state::metadata:
case state::ruleset:
case state::references:
case state::reference:
case state::reference_version:
Expand All @@ -193,6 +225,8 @@ class post_subject_versions_request_handler
case state::schema:
case state::id:
case state::version:
case state::metadata:
case state::ruleset:
case state::schema_type:
case state::reference:
case state::reference_name:
Expand Down Expand Up @@ -222,6 +256,8 @@ class post_subject_versions_request_handler
case state::schema:
case state::id:
case state::version:
case state::metadata:
case state::ruleset:
case state::schema_type:
case state::references:
case state::reference_name:
Expand Down
28 changes: 28 additions & 0 deletions tests/rptest/tests/schema_registry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,34 @@ def test_post_subjects_subject_versions_version_many(self):
assert result_raw.status_code == requests.codes.ok
assert result_raw.json()["id"] == 1

@cluster(num_nodes=3)
def test_post_subjects_subject_versions_metadata_ruleset(self):
"""
Verify posting a schema with metatada and ruleSet
These are not supported, but if they're null, we let it pass.
"""

topic = create_topic_names(1)[0]

self.logger.debug("Dump the schema with null metadata and ruleSet")
schema_1_data = json.dumps({
"schema": schema1_def,
"metadata": None,
"ruleSet": None
})

self.logger.debug("Posting schema as a subject key")
result_raw = self._post_subjects_subject_versions(
subject=f"{topic}-key", data=schema_1_data)
self.logger.debug(result_raw)
assert result_raw.status_code == requests.codes.ok

self.logger.debug("Retrieving schema")
result_raw = self._post_subjects_subject(subject=f"{topic}-key",
data=schema_1_data)
self.logger.debug(result_raw)
assert result_raw.status_code == requests.codes.ok

@cluster(num_nodes=3)
def test_post_subjects_subject(self):
"""
Expand Down

0 comments on commit 55bd576

Please sign in to comment.