From 2dc488e7a4a662ec92c036718c792695c76d6249 Mon Sep 17 00:00:00 2001 From: Pavel Bodiachevskii Date: Tue, 16 Apr 2024 03:11:17 +0400 Subject: [PATCH] refactor(avro schema): rename Avro*Schema to Avro* and move to 1.9.0 package https://github.com/asyncapi/jasyncapi/issues/185 --- .../{AvroSchema.java => v1/_9_0/Avro.java} | 22 +- .../_9_0/AvroArray.java} | 24 +- .../_9_0/AvroEnum.java} | 16 +- .../_9_0/AvroFixed.java} | 12 +- .../_9_0/AvroMap.java} | 24 +- .../avro/{ => v1/_9_0}/AvroMetadata.java | 2 +- .../_9_0/AvroRecord.java} | 28 +- .../_9_0/AvroRecordField.java} | 14 +- .../_9_0/AvroType.java} | 5 +- .../_9_0/jackson/AvroTypeDeserializer.java} | 12 +- .../v3/schema/avro/AvroSchemasProvider.kt | 532 +++++++++--------- .../avro/{AvroSchemaTest.kt => AvroTest.kt} | 13 +- 12 files changed, 367 insertions(+), 337 deletions(-) rename asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/{AvroSchema.java => v1/_9_0/Avro.java} (69%) rename asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/{AvroArraySchema.java => v1/_9_0/AvroArray.java} (52%) rename asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/{AvroEnumSchema.java => v1/_9_0/AvroEnum.java} (86%) rename asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/{AvroFixedSchema.java => v1/_9_0/AvroFixed.java} (84%) rename asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/{AvroMapSchema.java => v1/_9_0/AvroMap.java} (53%) rename asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/{ => v1/_9_0}/AvroMetadata.java (94%) rename asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/{AvroRecordSchema.java => v1/_9_0/AvroRecord.java} (68%) rename asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/{AvroRecordFieldSchema.java => v1/_9_0/AvroRecordField.java} (92%) rename asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/{AvroSchemaType.java => v1/_9_0/AvroType.java} (93%) rename asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/{jackson/AvroRecordFieldSchemaTypeDeserializer.java => v1/_9_0/jackson/AvroTypeDeserializer.java} (83%) rename asyncapi-core/src/test/kotlin/com/asyncapi/v3/schema/avro/{AvroSchemaTest.kt => AvroTest.kt} (88%) diff --git a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroSchema.java b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/Avro.java similarity index 69% rename from asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroSchema.java rename to asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/Avro.java index f2e060e6..3b615cfc 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroSchema.java +++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/Avro.java @@ -1,4 +1,4 @@ -package com.asyncapi.v3.schema.avro; +package com.asyncapi.v3.schema.avro.v1._9_0; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSubTypes; @@ -26,26 +26,26 @@ visible = true ) @JsonSubTypes({ - @JsonSubTypes.Type(value = AvroSchema.class, names = { + @JsonSubTypes.Type(value = Avro.class, names = { "null", "boolean", "int", "long", "float", "double", "bytes", "string" }), - @JsonSubTypes.Type(value = AvroRecordSchema.class, names = {"record", "error"}), - @JsonSubTypes.Type(value = AvroArraySchema.class, name = "array"), - @JsonSubTypes.Type(value = AvroMapSchema.class, name = "map"), - @JsonSubTypes.Type(value = AvroEnumSchema.class, name = "enum"), - @JsonSubTypes.Type(value = AvroFixedSchema.class, name = "fixed"), + @JsonSubTypes.Type(value = AvroRecord.class, names = {"record", "error"}), + @JsonSubTypes.Type(value = AvroArray.class, name = "array"), + @JsonSubTypes.Type(value = AvroMap.class, name = "map"), + @JsonSubTypes.Type(value = AvroEnum.class, name = "enum"), + @JsonSubTypes.Type(value = AvroFixed.class, name = "fixed"), }) -public class AvroSchema extends AvroMetadata { +public class Avro extends AvroMetadata { - public AvroSchema(@NotNull AvroSchemaType avroSchemaType) { - this.type = avroSchemaType; + public Avro(@NotNull AvroType avroType) { + this.type = avroType; } /** * Avro Schema type. */ @NotNull - private AvroSchemaType type; + private AvroType type; @Nullable private Integer scale; diff --git a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroArraySchema.java b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroArray.java similarity index 52% rename from asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroArraySchema.java rename to asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroArray.java index 48c4ab27..8df60659 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroArraySchema.java +++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroArray.java @@ -1,6 +1,6 @@ -package com.asyncapi.v3.schema.avro; +package com.asyncapi.v3.schema.avro.v1._9_0; -import com.asyncapi.v3.schema.avro.jackson.AvroRecordFieldSchemaTypeDeserializer; +import com.asyncapi.v3.schema.avro.v1._9_0.jackson.AvroTypeDeserializer; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import lombok.Builder; @@ -13,33 +13,33 @@ */ @Data @EqualsAndHashCode(callSuper = true) -public class AvroArraySchema extends AvroSchema { +public class AvroArray extends Avro { - public AvroArraySchema() { - super(AvroSchemaType.ARRAY); + public AvroArray() { + super(AvroType.ARRAY); } @Builder(builderMethodName = "arrayBuilder") - public AvroArraySchema( + public AvroArray( @NotNull Object items ) { - super(AvroSchemaType.ARRAY); + super(AvroType.ARRAY); this.items = items; } @NotNull @JsonProperty("items") - @JsonDeserialize(using = AvroRecordFieldSchemaTypeDeserializer.class) + @JsonDeserialize(using = AvroTypeDeserializer.class) private Object items; @NotNull @Override - public AvroSchemaType getType() { - return AvroSchemaType.ARRAY; + public AvroType getType() { + return AvroType.ARRAY; } - public void setType(@NotNull AvroSchemaType type) { - super.setType(AvroSchemaType.ARRAY); + public void setType(@NotNull AvroType type) { + super.setType(AvroType.ARRAY); } } diff --git a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroEnumSchema.java b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroEnum.java similarity index 86% rename from asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroEnumSchema.java rename to asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroEnum.java index f82d37f9..fe0446b8 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroEnumSchema.java +++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroEnum.java @@ -1,6 +1,6 @@ -package com.asyncapi.v3.schema.avro; +package com.asyncapi.v3.schema.avro.v1._9_0; -import com.asyncapi.v3.schema.avro.jackson.AvroRecordFieldSchemaTypeDeserializer; +import com.asyncapi.v3.schema.avro.v1._9_0.jackson.AvroTypeDeserializer; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import lombok.Builder; @@ -19,14 +19,14 @@ */ @Data @EqualsAndHashCode(callSuper = true) -public class AvroEnumSchema extends AvroSchema { +public class AvroEnum extends Avro { - public AvroEnumSchema() { - super(AvroSchemaType.ENUM); + public AvroEnum() { + super(AvroType.ENUM); } @Builder(builderMethodName = "enumBuilder") - public AvroEnumSchema( + public AvroEnum( @NotNull String name, @Nullable String namespace, @Nullable String doc, @@ -34,7 +34,7 @@ public AvroEnumSchema( @Nullable List<@NotNull String> aliases, @Nullable Object defaultValue ) { - super(AvroSchemaType.ENUM); + super(AvroType.ENUM); this.name = name; this.namespace = namespace; @@ -85,7 +85,7 @@ public AvroEnumSchema( */ @Nullable @JsonProperty("default") - @JsonDeserialize(using = AvroRecordFieldSchemaTypeDeserializer.class) + @JsonDeserialize(using = AvroTypeDeserializer.class) private Object defaultValue; } diff --git a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroFixedSchema.java b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroFixed.java similarity index 84% rename from asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroFixedSchema.java rename to asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroFixed.java index 092b446f..c74e4e2d 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroFixedSchema.java +++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroFixed.java @@ -1,4 +1,4 @@ -package com.asyncapi.v3.schema.avro; +package com.asyncapi.v3.schema.avro.v1._9_0; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; @@ -14,20 +14,20 @@ */ @Data @EqualsAndHashCode(callSuper = true) -public class AvroFixedSchema extends AvroSchema { +public class AvroFixed extends Avro { - public AvroFixedSchema() { - super(AvroSchemaType.FIXED); + public AvroFixed() { + super(AvroType.FIXED); } @Builder(builderMethodName = "fixedBuilder") - public AvroFixedSchema( + public AvroFixed( @NotNull String name, @Nullable String namespace, @Nullable List<@NotNull String> aliases, @NotNull Integer size ) { - super(AvroSchemaType.FIXED); + super(AvroType.FIXED); this.name = name; this.namespace = namespace; diff --git a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroMapSchema.java b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroMap.java similarity index 53% rename from asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroMapSchema.java rename to asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroMap.java index d1488029..01a48835 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroMapSchema.java +++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroMap.java @@ -1,6 +1,6 @@ -package com.asyncapi.v3.schema.avro; +package com.asyncapi.v3.schema.avro.v1._9_0; -import com.asyncapi.v3.schema.avro.jackson.AvroRecordFieldSchemaTypeDeserializer; +import com.asyncapi.v3.schema.avro.v1._9_0.jackson.AvroTypeDeserializer; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import lombok.Builder; @@ -16,35 +16,35 @@ */ @Data @EqualsAndHashCode(callSuper = true) -public class AvroMapSchema extends AvroSchema { +public class AvroMap extends Avro { - public AvroMapSchema() { - super(AvroSchemaType.MAP); + public AvroMap() { + super(AvroType.MAP); } - public AvroMapSchema(@NotNull Object values) { + public AvroMap(@NotNull Object values) { this.values = values; } @Builder(builderMethodName = "mapBuilder") - public AvroMapSchema(@NotNull Object values, @Nullable Map metadata) { + public AvroMap(@NotNull Object values, @Nullable Map metadata) { this.values = values; this.metadata = metadata; } @NotNull @JsonProperty("values") - @JsonDeserialize(using = AvroRecordFieldSchemaTypeDeserializer.class) + @JsonDeserialize(using = AvroTypeDeserializer.class) private Object values; @NotNull @Override - public AvroSchemaType getType() { - return AvroSchemaType.MAP; + public AvroType getType() { + return AvroType.MAP; } - public void setType(@NotNull AvroSchemaType type) { - super.setType(AvroSchemaType.MAP); + public void setType(@NotNull AvroType type) { + super.setType(AvroType.MAP); } } diff --git a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroMetadata.java b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroMetadata.java similarity index 94% rename from asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroMetadata.java rename to asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroMetadata.java index 80372d23..628bd1cf 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroMetadata.java +++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroMetadata.java @@ -1,4 +1,4 @@ -package com.asyncapi.v3.schema.avro; +package com.asyncapi.v3.schema.avro.v1._9_0; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroRecordSchema.java b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroRecord.java similarity index 68% rename from asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroRecordSchema.java rename to asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroRecord.java index bd49e0c3..272bd6d5 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroRecordSchema.java +++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroRecord.java @@ -1,4 +1,4 @@ -package com.asyncapi.v3.schema.avro; +package com.asyncapi.v3.schema.avro.v1._9_0; import lombok.*; import org.jetbrains.annotations.NotNull; @@ -16,25 +16,25 @@ */ @Data @EqualsAndHashCode(callSuper = true) -public class AvroRecordSchema extends AvroSchema { +public class AvroRecord extends Avro { - public AvroRecordSchema() { - super(AvroSchemaType.RECORD); + public AvroRecord() { + super(AvroType.RECORD); } @Builder(builderMethodName = "recordBuilder") - public AvroRecordSchema( - @Nullable AvroSchemaType type, + public AvroRecord( + @Nullable AvroType type, @NotNull String name, @Nullable String namespace, @Nullable String doc, @Nullable List<@NotNull String> aliases, - @NotNull List<@NotNull AvroRecordFieldSchema> fields + @NotNull List<@NotNull AvroRecordField> fields ) { - if (AvroSchemaType.RECORD.equals(type) || AvroSchemaType.ERROR.equals(type)) { + if (AvroType.RECORD.equals(type) || AvroType.ERROR.equals(type)) { super.setType(type); } else { - super.setType(AvroSchemaType.RECORD); + super.setType(AvroType.RECORD); } this.name = name; @@ -72,16 +72,16 @@ public AvroRecordSchema( * A JSON array, listing fields (required). */ @NotNull - private List<@NotNull AvroRecordFieldSchema> fields = Collections.emptyList(); + private List<@NotNull AvroRecordField> fields = Collections.emptyList(); @NotNull @Override - public AvroSchemaType getType() { - return AvroSchemaType.RECORD; + public AvroType getType() { + return AvroType.RECORD; } - public void setType(@NotNull AvroSchemaType type) { - super.setType(AvroSchemaType.RECORD); + public void setType(@NotNull AvroType type) { + super.setType(AvroType.RECORD); } } diff --git a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroRecordFieldSchema.java b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroRecordField.java similarity index 92% rename from asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroRecordFieldSchema.java rename to asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroRecordField.java index b886f41a..5d62e8b8 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroRecordFieldSchema.java +++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroRecordField.java @@ -1,6 +1,6 @@ -package com.asyncapi.v3.schema.avro; +package com.asyncapi.v3.schema.avro.v1._9_0; -import com.asyncapi.v3.schema.avro.jackson.AvroRecordFieldSchemaTypeDeserializer; +import com.asyncapi.v3.schema.avro.v1._9_0.jackson.AvroTypeDeserializer; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import lombok.Builder; @@ -21,14 +21,14 @@ */ @Data @EqualsAndHashCode(callSuper = true) -public class AvroRecordFieldSchema extends AvroMetadata { +public class AvroRecordField extends AvroMetadata { - public AvroRecordFieldSchema() { - this.type = AvroSchemaType.RECORD; + public AvroRecordField() { + this.type = AvroType.RECORD; } @Builder - public AvroRecordFieldSchema( + public AvroRecordField( @NotNull Object type, @NotNull String name, @Nullable Order order, @@ -51,7 +51,7 @@ public AvroRecordFieldSchema( */ @NotNull @JsonProperty("type") - @JsonDeserialize(using = AvroRecordFieldSchemaTypeDeserializer.class) + @JsonDeserialize(using = AvroTypeDeserializer.class) private Object type; /** diff --git a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroSchemaType.java b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroType.java similarity index 93% rename from asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroSchemaType.java rename to asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroType.java index 48137e14..913320ee 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroSchemaType.java +++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/AvroType.java @@ -1,8 +1,7 @@ -package com.asyncapi.v3.schema.avro; +package com.asyncapi.v3.schema.avro.v1._9_0; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import org.jetbrains.annotations.NotNull; /** * Apache Avro Schema types. @@ -12,7 +11,7 @@ * @see Avro Schema Primitive Types * @see Avro Schema Complex Types */ -public enum AvroSchemaType { +public enum AvroType { /* Primitive Types. diff --git a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/jackson/AvroRecordFieldSchemaTypeDeserializer.java b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/jackson/AvroTypeDeserializer.java similarity index 83% rename from asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/jackson/AvroRecordFieldSchemaTypeDeserializer.java rename to asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/jackson/AvroTypeDeserializer.java index f409589e..e8f3fbda 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/jackson/AvroRecordFieldSchemaTypeDeserializer.java +++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/v1/_9_0/jackson/AvroTypeDeserializer.java @@ -1,7 +1,7 @@ -package com.asyncapi.v3.schema.avro.jackson; +package com.asyncapi.v3.schema.avro.v1._9_0.jackson; -import com.asyncapi.v3.schema.avro.AvroSchema; -import com.asyncapi.v3.schema.avro.AvroSchemaType; +import com.asyncapi.v3.schema.avro.v1._9_0.Avro; +import com.asyncapi.v3.schema.avro.v1._9_0.AvroType; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.ObjectCodec; @@ -15,7 +15,7 @@ import java.util.ArrayList; import java.util.List; -public class AvroRecordFieldSchemaTypeDeserializer extends JsonDeserializer { +public class AvroTypeDeserializer extends JsonDeserializer { @Override final public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { @@ -37,9 +37,9 @@ private Object chooseKnownPojo(JsonNode jsonNode, final ObjectCodec objectCodec) case NUMBER: return jsonParser.readValueAs(Number.class); case OBJECT: - return jsonParser.readValueAs(AvroSchema.class); + return jsonParser.readValueAs(Avro.class); case STRING: - return jsonParser.readValueAs(AvroSchemaType.class); + return jsonParser.readValueAs(AvroType.class); case BINARY: case POJO: case MISSING: diff --git a/asyncapi-core/src/test/kotlin/com/asyncapi/v3/schema/avro/AvroSchemasProvider.kt b/asyncapi-core/src/test/kotlin/com/asyncapi/v3/schema/avro/AvroSchemasProvider.kt index e14cc847..67ab9f69 100644 --- a/asyncapi-core/src/test/kotlin/com/asyncapi/v3/schema/avro/AvroSchemasProvider.kt +++ b/asyncapi-core/src/test/kotlin/com/asyncapi/v3/schema/avro/AvroSchemasProvider.kt @@ -1,29 +1,31 @@ package com.asyncapi.v3.schema.avro +import com.asyncapi.v3.schema.avro.v1._9_0.* + class AvroSchemasProvider { - fun applicationEventTest(): AvroRecordSchema { - return AvroRecordSchema.recordBuilder() + fun applicationEventTest(): AvroRecord { + return AvroRecord.recordBuilder() .name("ApplicationEvent") .namespace("model") .doc("") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("applicationId") - .type(AvroSchemaType.STRING) + .type(AvroType.STRING) .doc("Application ID") .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("status") - .type(AvroSchemaType.STRING) + .type(AvroType.STRING) .doc("Application Status") .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("documents") // TODO: union type .type(listOf( - AvroSchemaType.NULL, - AvroArraySchema("model.DocumentInfo") + AvroType.NULL, + AvroArray("model.DocumentInfo") )) .doc("") .defaultValue(null) @@ -32,43 +34,43 @@ class AvroSchemasProvider { .build() } - fun documentInfo(): AvroRecordSchema { - return AvroRecordSchema.recordBuilder() + fun documentInfo(): AvroRecord { + return AvroRecord.recordBuilder() .name("DocumentInfo") .namespace("model") .doc("") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("documentId") - .type(AvroSchemaType.STRING) + .type(AvroType.STRING) .doc("Document ID") .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("filePath") - .type(AvroSchemaType.STRING) + .type(AvroType.STRING) .doc("Document Path") .build() )) .build() } - fun fooBar(): AvroRecordSchema { - return AvroRecordSchema.recordBuilder() + fun fooBar(): AvroRecord { + return AvroRecord.recordBuilder() .name("Bar") .namespace("foo") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("title") - .type(AvroSchemaType.STRING) + .type(AvroType.STRING) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("created_at") // TODO: union type .type(listOf( - AvroSchemaType.NULL, - AvroSchema.builder() - .type(AvroSchemaType.LONG) - .logicalType(AvroSchema.LogicalType.TIMESTAMP_MILLIS) + AvroType.NULL, + Avro.builder() + .type(AvroType.LONG) + .logicalType(Avro.LogicalType.TIMESTAMP_MILLIS) .build() )) .build() @@ -76,203 +78,206 @@ class AvroSchemasProvider { .build() } - fun fullRecordV1(): AvroRecordSchema { - return AvroRecordSchema.recordBuilder() + fun fullRecordV1(): AvroRecord { + return AvroRecord.recordBuilder() .name("FullRecordV1") .namespace("org.apache.avro.specific.test") .doc("Test schema changes: this is the 'old' schema the SpecificRecord expects to see") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("b") - .type(AvroSchemaType.BOOLEAN) + .type(AvroType.BOOLEAN) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("i32") - .type(AvroSchemaType.INT) + .type(AvroType.INT) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("i64") - .type(AvroSchemaType.LONG) + .type(AvroType.LONG) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("f32") - .type(AvroSchemaType.FLOAT) + .type(AvroType.FLOAT) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("f64") - .type(AvroSchemaType.DOUBLE) + .type(AvroType.DOUBLE) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("s") // TODO: union type .type(listOf( - AvroSchemaType.NULL, AvroSchemaType.STRING + AvroType.NULL, AvroType.STRING )) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("h") // TODO: union type .type(listOf( - AvroSchemaType.NULL, AvroSchemaType.STRING + AvroType.NULL, AvroType.STRING )) .build() )) .build() } - fun fullRecordV2(): AvroRecordSchema { - return AvroRecordSchema.recordBuilder() + fun fullRecordV2(): AvroRecord { + return AvroRecord.recordBuilder() .name("FullRecordV2") .namespace("org.apache.avro.specific.test") .doc("Test schema changes: this is the 'new' schema actually used to write data") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("b") - .type(AvroSchemaType.BOOLEAN) + .type(AvroType.BOOLEAN) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("i64") - .type(AvroSchemaType.INT) + .type(AvroType.INT) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("i32") - .type(AvroSchemaType.INT) + .type(AvroType.INT) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("f64") - .type(AvroSchemaType.LONG) + .type(AvroType.LONG) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("f32") // TODO: union type .type(listOf( - AvroSchemaType.FLOAT, AvroSchemaType.NULL + AvroType.FLOAT, AvroType.NULL )) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("newfield") - .type(AvroSchemaType.STRING) + .type(AvroType.STRING) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("h") - .type(AvroSchemaType.BYTES) + .type(AvroType.BYTES) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("myMap") - .type(AvroMapSchema(AvroSchemaType.STRING)) + .type(AvroMap(AvroType.STRING)) .build() )) .build() } - fun logicalUUID(): AvroRecordSchema { - return AvroRecordSchema.recordBuilder() + fun logicalUUID(): AvroRecord { + return AvroRecord.recordBuilder() .name("Action") .namespace("schema.common") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("name") - .type(AvroSchemaType.STRING) + .type(AvroType.STRING) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("guid") - .type(AvroSchema.builder() - .type(AvroSchemaType.STRING) - .logicalType(AvroSchema.LogicalType.UUID) + .type( + Avro.builder() + .type(AvroType.STRING) + .logicalType(Avro.LogicalType.UUID) .build() ) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("time") - .type(AvroSchema.builder() - .type(AvroSchemaType.LONG) - .logicalType(AvroSchema.LogicalType.TIMESTAMP_MILLIS) + .type( + Avro.builder() + .type(AvroType.LONG) + .logicalType(Avro.LogicalType.TIMESTAMP_MILLIS) .build() ) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requestId") // TODO: union type .type(listOf( - AvroSchemaType.NULL, AvroSchemaType.STRING + AvroType.NULL, AvroType.STRING )) .build() )) .build() } - fun logicalTypesWithMultipleFields(): AvroRecordSchema { - return AvroRecordSchema.recordBuilder() + fun logicalTypesWithMultipleFields(): AvroRecord { + return AvroRecord.recordBuilder() .name("Action") .namespace("schema.common") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("name") - .type(AvroSchemaType.STRING) + .type(AvroType.STRING) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("uuid") - .type(AvroSchemaType.STRING) + .type(AvroType.STRING) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("time") - .type(AvroSchema.builder() - .type(AvroSchemaType.LONG) - .logicalType(AvroSchema.LogicalType.TIMESTAMP_MILLIS) + .type( + Avro.builder() + .type(AvroType.LONG) + .logicalType(Avro.LogicalType.TIMESTAMP_MILLIS) .build() ) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requestId") // TODO: union type .type(listOf( - AvroSchemaType.NULL, AvroSchemaType.STRING + AvroType.NULL, AvroType.STRING )) .build() )) .build() } - fun myResponse(): AvroRecordSchema { - return AvroRecordSchema.recordBuilder() + fun myResponse(): AvroRecord { + return AvroRecord.recordBuilder() .name("MyResponse") .namespace("model") .doc("") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("isSuccessful") .doc("Indicator for successful or unsuccessful call") - .type(AvroSchemaType.BOOLEAN) + .type(AvroType.BOOLEAN) .build() )) .build() } - fun regressionErrorFieldInRecord(): AvroRecordSchema { - return AvroRecordSchema.recordBuilder() + fun regressionErrorFieldInRecord(): AvroRecord { + return AvroRecord.recordBuilder() .name("RecordWithErrorField") .namespace("org.apache.avro.specific.test") .doc("With custom coders in Avro 1.9, previously successful records with error fields now fail to compile.") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("s") // TODO: union type .type(listOf( - AvroSchemaType.NULL, AvroSchemaType.STRING + AvroType.NULL, AvroType.STRING )) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("e") // TODO: union type .type(listOf( - AvroSchemaType.NULL, AvroRecordSchema.recordBuilder() - .type(AvroSchemaType.ERROR) + AvroType.NULL, AvroRecord.recordBuilder() + .type(AvroType.ERROR) .name("TestError") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("message") - .type(AvroSchemaType.STRING) + .type(AvroType.STRING) .build() )) .build() @@ -283,49 +288,50 @@ class AvroSchemasProvider { .build() } - fun schemaLocation(): AvroRecordSchema { - val lat = AvroRecordFieldSchema.builder() + fun schemaLocation(): AvroRecord { + val lat = AvroRecordField.builder() .name("lat") - .type(AvroSchemaType.FLOAT) + .type(AvroType.FLOAT) .build() lat.metadata = mapOf(Pair("field-id", 1)) - val long = AvroRecordFieldSchema.builder() + val long = AvroRecordField.builder() .name("long") - .type(listOf(AvroSchemaType.NULL, AvroSchemaType.FLOAT)) + .type(listOf(AvroType.NULL, AvroType.FLOAT)) .defaultValue(null) .build() long.metadata = mapOf(Pair("field-id", 2)) - return AvroRecordSchema.recordBuilder() + return AvroRecord.recordBuilder() .name("r7") .fields(listOf(lat, long)) .build() } - fun schemaLocationRead(): AvroRecordSchema { - return AvroRecordSchema.recordBuilder() + fun schemaLocationRead(): AvroRecord { + return AvroRecord.recordBuilder() .name("table") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("location") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroMapSchema.mapBuilder() + .type(listOf( + AvroType.NULL, AvroMap.mapBuilder() // TODO: union type .values(listOf( - AvroSchemaType.NULL, - AvroRecordSchema.recordBuilder() + AvroType.NULL, + AvroRecord.recordBuilder() .name("r7") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("lat") - .type(AvroSchemaType.FLOAT) + .type(AvroType.FLOAT) .metadata(mapOf(Pair("field-id", 1))) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("long_r2") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroSchemaType.FLOAT)) + .type(listOf(AvroType.NULL, AvroType.FLOAT)) .defaultValue(null) .metadata(mapOf(Pair("field-id", 2))) .build() @@ -345,29 +351,30 @@ class AvroSchemasProvider { .build() } - fun schemaLocationWrite(): AvroRecordSchema { - return AvroRecordSchema.recordBuilder() + fun schemaLocationWrite(): AvroRecord { + return AvroRecord.recordBuilder() .name("table") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("location") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroMapSchema.mapBuilder() + .type(listOf( + AvroType.NULL, AvroMap.mapBuilder() // TODO: union type .values(listOf( - AvroSchemaType.NULL, - AvroRecordSchema.recordBuilder() + AvroType.NULL, + AvroRecord.recordBuilder() .name("r7") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("lat") - .type(AvroSchemaType.FLOAT) + .type(AvroType.FLOAT) .metadata(mapOf(Pair("field-id", 1))) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("long") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroSchemaType.FLOAT)) + .type(listOf(AvroType.NULL, AvroType.FLOAT)) .defaultValue(null) .metadata(mapOf(Pair("field-id", 2))) .build() @@ -387,357 +394,380 @@ class AvroSchemasProvider { .build() } - fun schemaBuilder(): AvroRecordSchema { - return AvroRecordSchema.recordBuilder() + fun schemaBuilder(): AvroRecord { + return AvroRecord.recordBuilder() .name("recordAll") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredBoolean") - .type(AvroSchemaType.BOOLEAN) + .type(AvroType.BOOLEAN) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredBooleanWithDefault") - .type(AvroSchemaType.BOOLEAN) + .type(AvroType.BOOLEAN) .defaultValue(true) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalBoolean") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroSchemaType.BOOLEAN)) + .type(listOf(AvroType.NULL, AvroType.BOOLEAN)) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalBooleanWithDefault") // TODO: union type - .type(listOf(AvroSchemaType.BOOLEAN, AvroSchemaType.NULL)) + .type(listOf(AvroType.BOOLEAN, AvroType.NULL)) .defaultValue(true) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredInt") - .type(AvroSchemaType.INT) + .type(AvroType.INT) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalInt") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroSchemaType.INT)) + .type(listOf(AvroType.NULL, AvroType.INT)) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalIntWithDefault") // TODO: union type - .type(listOf(AvroSchemaType.INT, AvroSchemaType.NULL)) + .type(listOf(AvroType.INT, AvroType.NULL)) .defaultValue(1) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredLong") - .type(AvroSchemaType.LONG) + .type(AvroType.LONG) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalLong") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroSchemaType.LONG)) + .type(listOf(AvroType.NULL, AvroType.LONG)) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalLongWithDefault") // TODO: union type - .type(listOf(AvroSchemaType.LONG, AvroSchemaType.NULL)) + .type(listOf(AvroType.LONG, AvroType.NULL)) .defaultValue(1) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredFloat") - .type(AvroSchemaType.FLOAT) + .type(AvroType.FLOAT) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalFloat") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroSchemaType.FLOAT)) + .type(listOf(AvroType.NULL, AvroType.FLOAT)) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalFloatWithDefault") // TODO: union type - .type(listOf(AvroSchemaType.FLOAT, AvroSchemaType.NULL)) + .type(listOf(AvroType.FLOAT, AvroType.NULL)) .defaultValue(1.0) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredDouble") - .type(AvroSchemaType.DOUBLE) + .type(AvroType.DOUBLE) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalDouble") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroSchemaType.DOUBLE)) + .type(listOf(AvroType.NULL, AvroType.DOUBLE)) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalDoubleWithDefault") // TODO: union type - .type(listOf(AvroSchemaType.DOUBLE, AvroSchemaType.NULL)) + .type(listOf(AvroType.DOUBLE, AvroType.NULL)) .defaultValue(1.0) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredBytes") - .type(AvroSchemaType.BYTES) + .type(AvroType.BYTES) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalBytes") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroSchemaType.BYTES)) + .type(listOf(AvroType.NULL, AvroType.BYTES)) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalBytesWithDefault") // TODO: union type - .type(listOf(AvroSchemaType.BYTES, AvroSchemaType.NULL)) + .type(listOf(AvroType.BYTES, AvroType.NULL)) .defaultValue("A") .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredString") - .type(AvroSchemaType.STRING) + .type(AvroType.STRING) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalString") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroSchemaType.STRING)) + .type(listOf(AvroType.NULL, AvroType.STRING)) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalStringWithDefault") // TODO: union type - .type(listOf(AvroSchemaType.STRING, AvroSchemaType.NULL)) + .type(listOf(AvroType.STRING, AvroType.NULL)) .defaultValue("a") .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredRecord") - .type(AvroRecordSchema.recordBuilder() + .type( + AvroRecord.recordBuilder() .name("nestedRequiredRecord") - .fields(listOf(AvroRecordFieldSchema.builder() + .fields(listOf( + AvroRecordField.builder() .name("nestedRequiredBoolean") - .type(AvroSchemaType.BOOLEAN) + .type(AvroType.BOOLEAN) .build()) ) .build() ) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalRecord") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroRecordSchema.recordBuilder() + .type(listOf( + AvroType.NULL, AvroRecord.recordBuilder() .name("nestedOptionalRecord") - .fields(listOf(AvroRecordFieldSchema.builder() + .fields(listOf( + AvroRecordField.builder() .name("nestedRequiredBoolean") - .type(AvroSchemaType.BOOLEAN) + .type(AvroType.BOOLEAN) .build()) ) .build() )) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalRecordWithDefault") // TODO: union type - .type(listOf(AvroRecordSchema.recordBuilder() + .type(listOf( + AvroRecord.recordBuilder() .name("nestedOptionalRecordWithDefault") - .fields(listOf(AvroRecordFieldSchema.builder() + .fields(listOf( + AvroRecordField.builder() .name("nestedRequiredBoolean") - .type(AvroSchemaType.BOOLEAN) + .type(AvroType.BOOLEAN) .build()) ) - .build(), AvroSchemaType.NULL + .build(), AvroType.NULL )) .defaultValue(mapOf(Pair("nestedRequiredBoolean", true))) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredEnum") - .type(AvroEnumSchema.enumBuilder() + .type( + AvroEnum.enumBuilder() .name("requiredEnum") .symbols(listOf("a", "b")) .build() ) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalEnum") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroEnumSchema.enumBuilder() + .type(listOf( + AvroType.NULL, AvroEnum.enumBuilder() .name("optionalEnum") .symbols(listOf("a", "b")) .build() )) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalEnumWithDefault") // TODO: union type - .type(listOf(AvroEnumSchema.enumBuilder() + .type(listOf( + AvroEnum.enumBuilder() .name("optionalEnumWithDefault") .symbols(listOf("a", "b")) - .build(), AvroSchemaType.NULL, + .build(), AvroType.NULL, )) .defaultValue("b") .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredArray") - .type(AvroArraySchema.arrayBuilder() - .items(AvroSchemaType.STRING) + .type( + AvroArray.arrayBuilder() + .items(AvroType.STRING) .build() ) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalArray") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroArraySchema.arrayBuilder() - .items(AvroSchemaType.STRING) + .type(listOf( + AvroType.NULL, AvroArray.arrayBuilder() + .items(AvroType.STRING) .build() )) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalArrayWithDefault") // TODO: union type - .type(listOf(AvroArraySchema.arrayBuilder() - .items(AvroSchemaType.STRING) - .build(), AvroSchemaType.NULL + .type(listOf( + AvroArray.arrayBuilder() + .items(AvroType.STRING) + .build(), AvroType.NULL )) .defaultValue(listOf("a")) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredMap") - .type(AvroMapSchema.mapBuilder() - .values(AvroSchemaType.STRING) + .type( + AvroMap.mapBuilder() + .values(AvroType.STRING) .build() ) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalMap") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroMapSchema.mapBuilder() - .values(AvroSchemaType.STRING) + .type(listOf( + AvroType.NULL, AvroMap.mapBuilder() + .values(AvroType.STRING) .build() )) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalMapWithDefault") // TODO: union type - .type(listOf(AvroMapSchema.mapBuilder() - .values(AvroSchemaType.STRING) - .build(), AvroSchemaType.NULL + .type(listOf( + AvroMap.mapBuilder() + .values(AvroType.STRING) + .build(), AvroType.NULL )) .defaultValue(mapOf(Pair("a", "b"))) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("requiredFixed") - .type(AvroFixedSchema.fixedBuilder() + .type( + AvroFixed.fixedBuilder() .name("requiredFixed") .size(1) .build() ) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalFixed") // TODO: union type - .type(listOf(AvroSchemaType.NULL, AvroFixedSchema.fixedBuilder() + .type(listOf( + AvroType.NULL, AvroFixed.fixedBuilder() .name("optionalFixed") .size(1) .build() )) .defaultValue(null) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("optionalFixedWithDefault") // TODO: union type - .type(listOf(AvroFixedSchema.fixedBuilder() + .type(listOf( + AvroFixed.fixedBuilder() .name("optionalFixedWithDefault") .size(1) - .build(), AvroSchemaType.NULL + .build(), AvroType.NULL )) .defaultValue("A") .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionType") - .type(listOf(AvroSchemaType.LONG, AvroSchemaType.NULL)) + .type(listOf(AvroType.LONG, AvroType.NULL)) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionBooleanWithDefault") - .type(listOf(AvroSchemaType.BOOLEAN, AvroSchemaType.INT)) + .type(listOf(AvroType.BOOLEAN, AvroType.INT)) .defaultValue(true) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionIntWithDefault") - .type(listOf(AvroSchemaType.INT, AvroSchemaType.NULL)) + .type(listOf(AvroType.INT, AvroType.NULL)) .defaultValue(1) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionLongWithDefault") - .type(listOf(AvroSchemaType.LONG, AvroSchemaType.INT)) + .type(listOf(AvroType.LONG, AvroType.INT)) .defaultValue(1) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionFloatWithDefault") - .type(listOf(AvroSchemaType.FLOAT, AvroSchemaType.INT)) + .type(listOf(AvroType.FLOAT, AvroType.INT)) .defaultValue(1.0) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionDoubleWithDefault") - .type(listOf(AvroSchemaType.DOUBLE, AvroSchemaType.INT)) + .type(listOf(AvroType.DOUBLE, AvroType.INT)) .defaultValue(1.0) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionBytesWithDefault") - .type(listOf(AvroSchemaType.BYTES, AvroSchemaType.INT)) + .type(listOf(AvroType.BYTES, AvroType.INT)) .defaultValue("A") .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionStringWithDefault") - .type(listOf(AvroSchemaType.STRING, AvroSchemaType.INT)) + .type(listOf(AvroType.STRING, AvroType.INT)) .defaultValue("a") .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionRecordWithDefault") - .type(listOf(AvroRecordSchema.recordBuilder() + .type(listOf( + AvroRecord.recordBuilder() .name("nestedUnionRecordWithDefault") .fields(listOf( - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("nestedRequiredBoolean") - .type(AvroSchemaType.BOOLEAN) + .type(AvroType.BOOLEAN) .build() )) - .build(), AvroSchemaType.INT + .build(), AvroType.INT )) .defaultValue(mapOf(Pair("nestedRequiredBoolean", true))) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionEnumWithDefault") - .type(listOf(AvroEnumSchema.enumBuilder() + .type(listOf( + AvroEnum.enumBuilder() .name("nestedUnionEnumWithDefault") .symbols(listOf("a", "b")) - .build(), AvroSchemaType.INT + .build(), AvroType.INT )) .defaultValue("b") .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionArrayWithDefault") - .type(listOf(AvroArraySchema.arrayBuilder() - .items(AvroSchemaType.STRING) - .build(), AvroSchemaType.INT + .type(listOf( + AvroArray.arrayBuilder() + .items(AvroType.STRING) + .build(), AvroType.INT )) .defaultValue(listOf("a")) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionMapWithDefault") - .type(listOf(AvroMapSchema.mapBuilder() - .values(AvroSchemaType.STRING) - .build(), AvroSchemaType.INT + .type(listOf( + AvroMap.mapBuilder() + .values(AvroType.STRING) + .build(), AvroType.INT )) .defaultValue(mapOf(Pair("a", "b"))) .build(), - AvroRecordFieldSchema.builder() + AvroRecordField.builder() .name("unionFixedWithDefault") - .type(listOf(AvroFixedSchema.fixedBuilder() + .type(listOf( + AvroFixed.fixedBuilder() .name("nestedUnionFixedWithDefault") .size(1) - .build(), AvroSchemaType.INT + .build(), AvroType.INT )) .defaultValue("A") .build(), diff --git a/asyncapi-core/src/test/kotlin/com/asyncapi/v3/schema/avro/AvroSchemaTest.kt b/asyncapi-core/src/test/kotlin/com/asyncapi/v3/schema/avro/AvroTest.kt similarity index 88% rename from asyncapi-core/src/test/kotlin/com/asyncapi/v3/schema/avro/AvroSchemaTest.kt rename to asyncapi-core/src/test/kotlin/com/asyncapi/v3/schema/avro/AvroTest.kt index 07fc0716..c15e02f0 100644 --- a/asyncapi-core/src/test/kotlin/com/asyncapi/v3/schema/avro/AvroSchemaTest.kt +++ b/asyncapi-core/src/test/kotlin/com/asyncapi/v3/schema/avro/AvroTest.kt @@ -1,6 +1,7 @@ package com.asyncapi.v3.schema.avro import com.asyncapi.v3.ClasspathUtils +import com.asyncapi.v3.schema.avro.v1._9_0.Avro import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.dataformat.yaml.YAMLFactory @@ -16,10 +17,10 @@ class AvroSchemaTest { fun compareSchemas( schemaToCheckPath: String, - schemaToCheck: AvroSchema + schemaToCheck: Avro ) { val schemaAsJson = ClasspathUtils.readAsString(schemaToCheckPath) - val schema = objectMapper.readValue(schemaAsJson, AvroSchema::class.java) + val schema = objectMapper.readValue(schemaAsJson, Avro::class.java) Assertions.assertEquals(schema, schemaToCheck) } @@ -28,17 +29,17 @@ class AvroSchemaTest { .setSerializationInclusion(JsonInclude.Include.NON_NULL) .findAndRegisterModules() - @ArgumentsSource(Avro::class) + @ArgumentsSource(AvroSchemas::class) @ParameterizedTest(name = "Read: {0}") - fun read(schemaToCheckPath: String, avroSchema: AvroSchema) { + fun read(schemaToCheckPath: String, avroSchema: Avro) { compareSchemas(schemaToCheckPath, avroSchema) } - class Avro: ArgumentsProvider { + class AvroSchemas: ArgumentsProvider { override fun provideArguments(context: ExtensionContext?): Stream { return Stream.of( -// Arguments.of("/json/v3/schema/avro/ApplicationEvent.avsc", AvroSchemasProvider().applicationEventTest()), // TODO: fix - Cannot deserialize value of type `com.asyncapi.v3.schema.avro.AvroSchemaType` from String "model.DocumentInfo" +// Arguments.of("/json/v3/schema/avro/ApplicationEvent.avsc", AvroSchemasProvider().applicationEventTest()), // TODO: fix - Cannot deserialize value of type `com.asyncapi.v3.schema.avro.v1._9_0.AvroSchemaType` from String "model.DocumentInfo" Arguments.of("/json/v3/schema/avro/DocumentInfo.avsc", AvroSchemasProvider().documentInfo()), Arguments.of("/json/v3/schema/avro/foo.Bar.avsc", AvroSchemasProvider().fooBar()), Arguments.of("/json/v3/schema/avro/full_record_v1.avsc", AvroSchemasProvider().fullRecordV1()),