From b572a6e8663e6911a5ebfca87ae5da2a335e1988 Mon Sep 17 00:00:00 2001 From: Ildar Almakaev Date: Wed, 10 Mar 2021 09:20:37 +0300 Subject: [PATCH] For backward compatibility with Schema Registry API set schemaType as optional in NewSchemaSubject and ignore if it's NULL --- .../schemaregistry/InternalNewSchema.java | 2 ++ .../kafka/ui/SchemaRegistryServiceTests.java | 20 +++++++++++++++++++ .../main/resources/swagger/kafka-ui-api.yaml | 1 - 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/kafka-ui-api/src/main/java/com/provectus/kafka/ui/cluster/model/schemaregistry/InternalNewSchema.java b/kafka-ui-api/src/main/java/com/provectus/kafka/ui/cluster/model/schemaregistry/InternalNewSchema.java index 00a41217cc..d607992d5f 100644 --- a/kafka-ui-api/src/main/java/com/provectus/kafka/ui/cluster/model/schemaregistry/InternalNewSchema.java +++ b/kafka-ui-api/src/main/java/com/provectus/kafka/ui/cluster/model/schemaregistry/InternalNewSchema.java @@ -1,5 +1,6 @@ package com.provectus.kafka.ui.cluster.model.schemaregistry; +import com.fasterxml.jackson.annotation.JsonInclude; import com.provectus.kafka.ui.model.NewSchemaSubject; import com.provectus.kafka.ui.model.SchemaType; import lombok.Data; @@ -7,6 +8,7 @@ import lombok.Data; @Data public class InternalNewSchema { private String schema; + @JsonInclude(JsonInclude.Include.NON_NULL) private SchemaType schemaType; public InternalNewSchema(NewSchemaSubject schemaSubject) { diff --git a/kafka-ui-api/src/test/java/com/provectus/kafka/ui/SchemaRegistryServiceTests.java b/kafka-ui-api/src/test/java/com/provectus/kafka/ui/SchemaRegistryServiceTests.java index 7f867ef26f..df73ba8b96 100644 --- a/kafka-ui-api/src/test/java/com/provectus/kafka/ui/SchemaRegistryServiceTests.java +++ b/kafka-ui-api/src/test/java/com/provectus/kafka/ui/SchemaRegistryServiceTests.java @@ -54,6 +54,26 @@ class SchemaRegistryServiceTests extends AbstractBaseTest { .expectStatus().isNotFound(); } + /** + * It should create a new schema w/o submitting a schemaType field to Schema Registry + */ + @Test + void shouldCreateNewSchemaWhenSchemaTypeNotPresents() { + String schema = "{\"subject\":\"%s\",\"schema\":\"{\\\"type\\\": \\\"string\\\"}\"}"; + + SchemaSubject actualResponse = webTestClient + .post() + .uri("/api/clusters/{clusterName}/schemas", LOCAL) + .contentType(MediaType.APPLICATION_JSON) + .body(BodyInserters.fromValue(schema.formatted(subject))) + .exchange() + .expectStatus().isEqualTo(HttpStatus.OK) + .expectBody(SchemaSubject.class).returnResult().getResponseBody(); + + Assertions.assertNotNull(actualResponse); + Assertions.assertEquals(SchemaType.AVRO, actualResponse.getSchemaType()); + } + @Test void shouldReturn409WhenSchemaDuplicatesThePreviousVersion() { String schema = "{\"subject\":\"%s\",\"schemaType\":\"AVRO\",\"schema\":\"{\\\"type\\\": \\\"string\\\"}\"}"; diff --git a/kafka-ui-contract/src/main/resources/swagger/kafka-ui-api.yaml b/kafka-ui-contract/src/main/resources/swagger/kafka-ui-api.yaml index f50695abfc..8e0032a5bc 100644 --- a/kafka-ui-contract/src/main/resources/swagger/kafka-ui-api.yaml +++ b/kafka-ui-contract/src/main/resources/swagger/kafka-ui-api.yaml @@ -1381,7 +1381,6 @@ components: required: - subject - schema - - schemaType CompatibilityLevel: type: object