From 68cdd7b9cc9a38a60db3cf2df8c46582047c3ce9 Mon Sep 17 00:00:00 2001 From: Ben Pope Date: Fri, 22 Jul 2022 11:18:37 +0100 Subject: [PATCH 1/2] 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) From 2412a2485c676bdadd236df7df7a2b29ee221281 Mon Sep 17 00:00:00 2001 From: Ben Pope Date: Fri, 22 Jul 2022 11:26:32 +0100 Subject: [PATCH 2/2] schema_registry: Update swagger for get_schemas_ids_id The `schemaType` is now returned if it's not avro. Signed-off-by: Ben Pope --- src/v/pandaproxy/api/api-doc/schema_registry.json | 3 +++ src/v/pandaproxy/api/api-doc/schema_registry_header.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/v/pandaproxy/api/api-doc/schema_registry.json b/src/v/pandaproxy/api/api-doc/schema_registry.json index 1a14d326e9a2..dd81567ec34e 100644 --- a/src/v/pandaproxy/api/api-doc/schema_registry.json +++ b/src/v/pandaproxy/api/api-doc/schema_registry.json @@ -247,6 +247,9 @@ "schema": { "type": "object", "properties": { + "schemaType": { + "type": "string" + }, "schema": { "type": "string" } diff --git a/src/v/pandaproxy/api/api-doc/schema_registry_header.json b/src/v/pandaproxy/api/api-doc/schema_registry_header.json index 8b05197f0d3a..933acad57f93 100644 --- a/src/v/pandaproxy/api/api-doc/schema_registry_header.json +++ b/src/v/pandaproxy/api/api-doc/schema_registry_header.json @@ -2,7 +2,7 @@ "swagger": "2.0", "info": { "title": "Pandaproxy Schema Registry", - "version": "1.0.0" + "version": "1.0.1" }, "host": "{{Host}}", "basePath": "/",