From 68cdd7b9cc9a38a60db3cf2df8c46582047c3ce9 Mon Sep 17 00:00:00 2001 From: Ben Pope Date: Fri, 22 Jul 2022 11:18:37 +0100 Subject: [PATCH] schema_registry: Return schemaType for /schemas/ids/ If the schema type is not avro, then set schemaType field in the response. Signed-off-by: Ben Pope --- .../schema_registry/requests/get_schemas_ids_id.h | 4 ++++ tests/rptest/tests/schema_registry_test.py | 9 +++++++++ 2 files changed, 13 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 5e15b7877d9c..04a5a083ed42 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 @@ -24,6 +24,10 @@ inline void rjson_serialize( ::json::Writer<::json::StringBuffer>& w, const get_schemas_ids_id_response& res) { w.StartObject(); + if (res.definition.type() != schema_type::avro) { + w.Key("schemaType"); + ::json::rjson_serialize(w, to_string_view(res.definition.type())); + } w.Key("schema"); ::json::rjson_serialize(w, res.definition.raw()); w.EndObject(); diff --git a/tests/rptest/tests/schema_registry_test.py b/tests/rptest/tests/schema_registry_test.py index 7c2a9b9860ee..6032d28b5808 100644 --- a/tests/rptest/tests/schema_registry_test.py +++ b/tests/rptest/tests/schema_registry_test.py @@ -1037,6 +1037,15 @@ def test_protobuf(self): assert result_raw.status_code == requests.codes.ok assert result_raw.text.strip() == simple_proto_def.strip() + result_raw = self._request("GET", + f"schemas/ids/1", + headers=HTTP_GET_HEADERS) + self.logger.info(result_raw) + assert result_raw.status_code == requests.codes.ok + result = result_raw.json() + assert result["schemaType"] == "PROTOBUF" + assert result["schema"].strip() == simple_proto_def.strip() + result_raw = self._get_subjects_subject_versions_version_referenced_by( "simple", 1) self.logger.info(result_raw)