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/AvroArraySchema.java
index e2543a6c..48c4ab27 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/AvroArraySchema.java
@@ -1,19 +1,45 @@
package com.asyncapi.v3.schema.avro;
+import com.asyncapi.v3.schema.avro.jackson.AvroRecordFieldSchemaTypeDeserializer;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import lombok.Builder;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
/**
* @see Arrays
*/
+@Data
+@EqualsAndHashCode(callSuper = true)
public class AvroArraySchema extends AvroSchema {
public AvroArraySchema() {
super(AvroSchemaType.ARRAY);
}
+ @Builder(builderMethodName = "arrayBuilder")
+ public AvroArraySchema(
+ @NotNull Object items
+ ) {
+ super(AvroSchemaType.ARRAY);
+ this.items = items;
+ }
+
@NotNull
@JsonProperty("items")
- private String items;
+ @JsonDeserialize(using = AvroRecordFieldSchemaTypeDeserializer.class)
+ private Object items;
+
+ @NotNull
+ @Override
+ public AvroSchemaType getType() {
+ return AvroSchemaType.ARRAY;
+ }
+
+ public void setType(@NotNull AvroSchemaType type) {
+ super.setType(AvroSchemaType.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/AvroEnumSchema.java
index 4fe12a8d..f82d37f9 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/AvroEnumSchema.java
@@ -1,6 +1,11 @@
package com.asyncapi.v3.schema.avro;
+import com.asyncapi.v3.schema.avro.jackson.AvroRecordFieldSchemaTypeDeserializer;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import lombok.Builder;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -12,12 +17,33 @@
*
* @see Enums
*/
+@Data
+@EqualsAndHashCode(callSuper = true)
public class AvroEnumSchema extends AvroSchema {
public AvroEnumSchema() {
super(AvroSchemaType.ENUM);
}
+ @Builder(builderMethodName = "enumBuilder")
+ public AvroEnumSchema(
+ @NotNull String name,
+ @Nullable String namespace,
+ @Nullable String doc,
+ @NotNull List<@NotNull String> symbols,
+ @Nullable List<@NotNull String> aliases,
+ @Nullable Object defaultValue
+ ) {
+ super(AvroSchemaType.ENUM);
+
+ this.name = name;
+ this.namespace = namespace;
+ this.doc = doc;
+ this.symbols = symbols;
+ this.aliases = aliases;
+ this.defaultValue = defaultValue;
+ }
+
@NotNull
@JsonProperty("name")
private String name = "";
@@ -59,6 +85,7 @@ public AvroEnumSchema() {
*/
@Nullable
@JsonProperty("default")
- private String defaultValue;
+ @JsonDeserialize(using = AvroRecordFieldSchemaTypeDeserializer.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/AvroFixedSchema.java
index 7aba05ed..092b446f 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/AvroFixedSchema.java
@@ -1,6 +1,9 @@
package com.asyncapi.v3.schema.avro;
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Builder;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -9,12 +12,29 @@
/**
* @see Arrays
*/
+@Data
+@EqualsAndHashCode(callSuper = true)
public class AvroFixedSchema extends AvroSchema {
public AvroFixedSchema() {
super(AvroSchemaType.FIXED);
}
+ @Builder(builderMethodName = "fixedBuilder")
+ public AvroFixedSchema(
+ @NotNull String name,
+ @Nullable String namespace,
+ @Nullable List<@NotNull String> aliases,
+ @NotNull Integer size
+ ) {
+ super(AvroSchemaType.FIXED);
+
+ this.name = name;
+ this.namespace = namespace;
+ this.aliases = aliases;
+ this.size = size;
+ }
+
@NotNull
@JsonProperty("name")
private String name;
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/AvroMapSchema.java
index 1b0ecfd3..d1488029 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/AvroMapSchema.java
@@ -1,19 +1,50 @@
package com.asyncapi.v3.schema.avro;
+import com.asyncapi.v3.schema.avro.jackson.AvroRecordFieldSchemaTypeDeserializer;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import lombok.Builder;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Map;
/**
* @see Maps
*/
+@Data
+@EqualsAndHashCode(callSuper = true)
public class AvroMapSchema extends AvroSchema {
public AvroMapSchema() {
super(AvroSchemaType.MAP);
}
+ public AvroMapSchema(@NotNull Object values) {
+ this.values = values;
+ }
+
+ @Builder(builderMethodName = "mapBuilder")
+ public AvroMapSchema(@NotNull Object values, @Nullable Map metadata) {
+ this.values = values;
+ this.metadata = metadata;
+ }
+
@NotNull
@JsonProperty("values")
- private String values;
+ @JsonDeserialize(using = AvroRecordFieldSchemaTypeDeserializer.class)
+ private Object values;
+
+ @NotNull
+ @Override
+ public AvroSchemaType getType() {
+ return AvroSchemaType.MAP;
+ }
+
+ public void setType(@NotNull AvroSchemaType type) {
+ super.setType(AvroSchemaType.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/AvroMetadata.java
new file mode 100644
index 00000000..80372d23
--- /dev/null
+++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroMetadata.java
@@ -0,0 +1,33 @@
+package com.asyncapi.v3.schema.avro;
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter;
+import com.fasterxml.jackson.annotation.JsonAnySetter;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@JsonIgnoreProperties({"metadata"})
+public class AvroMetadata {
+
+ @Nullable
+ @JsonAnyGetter
+ protected Map metadata;
+
+ @JsonAnySetter
+ protected final void readMetadata(String name, Object value) {
+ if (metadata == null) {
+ metadata = new HashMap<>();
+ }
+
+ metadata.put(name, value);
+ }
+
+}
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/AvroRecordFieldSchema.java
index a53a54d4..b886f41a 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/AvroRecordFieldSchema.java
@@ -1,11 +1,16 @@
package com.asyncapi.v3.schema.avro;
+import com.asyncapi.v3.schema.avro.jackson.AvroRecordFieldSchemaTypeDeserializer;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import lombok.Builder;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.Collections;
import java.util.List;
+import java.util.Map;
/**
* Avro Record Field.
@@ -14,10 +19,31 @@
* @version 3.0.0
* @see Avro Record
*/
-public class AvroRecordFieldSchema extends AvroSchema {
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class AvroRecordFieldSchema extends AvroMetadata {
public AvroRecordFieldSchema() {
- super(AvroSchemaType.RECORD);
+ this.type = AvroSchemaType.RECORD;
+ }
+
+ @Builder
+ public AvroRecordFieldSchema(
+ @NotNull Object type,
+ @NotNull String name,
+ @Nullable Order order,
+ @Nullable String doc,
+ @Nullable List<@NotNull String> aliases,
+ @Nullable Object defaultValue,
+ @Nullable Map metadata
+ ) {
+ this.type = type;
+ this.name = name;
+ this.order = order == null ? Order.ASCENDING : order ;
+ this.doc = doc;
+ this.aliases = aliases;
+ this.defaultValue = defaultValue;
+ this.metadata = metadata;
}
/**
@@ -25,6 +51,7 @@ public AvroRecordFieldSchema() {
*/
@NotNull
@JsonProperty("type")
+ @JsonDeserialize(using = AvroRecordFieldSchemaTypeDeserializer.class)
private Object type;
/**
@@ -37,9 +64,23 @@ public AvroRecordFieldSchema() {
/**
* Specifies how this field impacts sort ordering of this record (optional).
*/
- @Nullable("order")
+ @Nullable
+ @JsonProperty("order")
private Order order = Order.ASCENDING;
+ @NotNull
+ public Order getOrder() {
+ if (order == null) {
+ setOrder(Order.ASCENDING);
+ }
+
+ return order;
+ }
+
+ public void setOrder(@NotNull Order order) {
+ this.order = order;
+ }
+
/**
* A JSON string providing documentation to the user of this schema (optional).
*/
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/AvroRecordSchema.java
index 464ba693..bd49e0c3 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/AvroRecordSchema.java
@@ -1,5 +1,6 @@
package com.asyncapi.v3.schema.avro;
+import lombok.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -13,12 +14,36 @@
* @version 3.0.0
* @see Avro Record
*/
+@Data
+@EqualsAndHashCode(callSuper = true)
public class AvroRecordSchema extends AvroSchema {
public AvroRecordSchema() {
super(AvroSchemaType.RECORD);
}
+ @Builder(builderMethodName = "recordBuilder")
+ public AvroRecordSchema(
+ @Nullable AvroSchemaType type,
+ @NotNull String name,
+ @Nullable String namespace,
+ @Nullable String doc,
+ @Nullable List<@NotNull String> aliases,
+ @NotNull List<@NotNull AvroRecordFieldSchema> fields
+ ) {
+ if (AvroSchemaType.RECORD.equals(type) || AvroSchemaType.ERROR.equals(type)) {
+ super.setType(type);
+ } else {
+ super.setType(AvroSchemaType.RECORD);
+ }
+
+ this.name = name;
+ this.namespace = namespace;
+ this.doc = doc;
+ this.aliases = aliases;
+ this.fields = fields;
+ }
+
/**
* A JSON string providing the name of the record (required).
*/
@@ -49,4 +74,14 @@ public AvroRecordSchema() {
@NotNull
private List<@NotNull AvroRecordFieldSchema> fields = Collections.emptyList();
+ @NotNull
+ @Override
+ public AvroSchemaType getType() {
+ return AvroSchemaType.RECORD;
+ }
+
+ public void setType(@NotNull AvroSchemaType type) {
+ super.setType(AvroSchemaType.RECORD);
+ }
+
}
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/AvroSchema.java
index 9273f76d..f2e060e6 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/AvroSchema.java
@@ -1,9 +1,11 @@
package com.asyncapi.v3.schema.avro;
+import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import lombok.Data;
+import lombok.*;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
/**
* Apache Avro Schema.
@@ -13,16 +15,31 @@
* @see Avro Specification
*/
@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@EqualsAndHashCode(callSuper = true)
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
property = "type",
visible = true
)
-@JsonSubTypes.Type(value = AvroSchema.class, names = {
- "null", "boolean", "int", "long", "float", "double", "bytes", "string"
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = AvroSchema.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"),
})
-public class AvroSchema {
+public class AvroSchema extends AvroMetadata {
+
+ public AvroSchema(@NotNull AvroSchemaType avroSchemaType) {
+ this.type = avroSchemaType;
+ }
/**
* Avro Schema type.
@@ -30,4 +47,45 @@ public class AvroSchema {
@NotNull
private AvroSchemaType type;
+ @Nullable
+ private Integer scale;
+
+ /*
+ Type: bytes, fixed
+ */
+
+ @Nullable
+ private Integer precision;
+
+ @Nullable
+ private LogicalType logicalType;
+
+ public enum LogicalType {
+
+ @JsonProperty("decimal")
+ DECIMAL,
+
+ @JsonProperty("uuid")
+ UUID,
+
+ @JsonProperty("date")
+ DATE,
+
+ @JsonProperty("time-millis")
+ TIME_MILLIS,
+
+ @JsonProperty("time-micros")
+ TIME_MICROS,
+
+ @JsonProperty("timestamp-millis")
+ TIMESTAMP_MILLIS,
+
+ @JsonProperty("timestamp-micros")
+ TIMESTAMP_MICROS,
+
+ @JsonProperty("duration")
+ DURATION
+
+ }
+
}
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/jackson/AvroRecordFieldSchemaTypeDeserializer.java
new file mode 100644
index 00000000..f409589e
--- /dev/null
+++ b/asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/jackson/AvroRecordFieldSchemaTypeDeserializer.java
@@ -0,0 +1,63 @@
+package com.asyncapi.v3.schema.avro.jackson;
+
+import com.asyncapi.v3.schema.avro.AvroSchema;
+import com.asyncapi.v3.schema.avro.AvroSchemaType;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeType;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class AvroRecordFieldSchemaTypeDeserializer extends JsonDeserializer