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

This commit is contained in:
Ildar Almakaev 2021-03-10 09:20:37 +03:00
parent 95e66754e1
commit b572a6e866
3 changed files with 22 additions and 1 deletions

View file

@ -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) {

View file

@ -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\\\"}\"}";

View file

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