瀏覽代碼

For backward compatibility with Schema Registry API set schemaType as optional in NewSchemaSubject and ignore if it's NULL

Ildar Almakaev 4 年之前
父節點
當前提交
b572a6e866

+ 2 - 0
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) {

+ 20 - 0
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\\\"}\"}";

+ 0 - 1
kafka-ui-contract/src/main/resources/swagger/kafka-ui-api.yaml

@@ -1381,7 +1381,6 @@ components:
       required:
         - subject
         - schema
-        - schemaType
 
     CompatibilityLevel:
       type: object