Skip to content

Commit

Permalink
refactor(avro schema): rename Avro*Schema to Avro* and move to 1.9.0 …
Browse files Browse the repository at this point in the history
…package

#185
  • Loading branch information
Pakisan committed Apr 15, 2024
1 parent 1018622 commit 2dc488e
Show file tree
Hide file tree
Showing 12 changed files with 367 additions and 337 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,22 +19,22 @@
*/
@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,
@NotNull List<@NotNull String> symbols,
@Nullable List<@NotNull String> aliases,
@Nullable Object defaultValue
) {
super(AvroSchemaType.ENUM);
super(AvroType.ENUM);

this.name = name;
this.namespace = namespace;
Expand Down Expand Up @@ -85,7 +85,7 @@ public AvroEnumSchema(
*/
@Nullable
@JsonProperty("default")
@JsonDeserialize(using = AvroRecordFieldSchemaTypeDeserializer.class)
@JsonDeserialize(using = AvroTypeDeserializer.class)
private Object defaultValue;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String, Object> metadata) {
public AvroMap(@NotNull Object values, @Nullable Map<String, Object> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -51,7 +51,7 @@ public AvroRecordFieldSchema(
*/
@NotNull
@JsonProperty("type")
@JsonDeserialize(using = AvroRecordFieldSchemaTypeDeserializer.class)
@JsonDeserialize(using = AvroTypeDeserializer.class)
private Object type;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -12,7 +11,7 @@
* @see <a href="https://avro.apache.org/docs/1.9.0/spec.html#schema_primitive">Avro Schema Primitive Types</a>
* @see <a href="https://avro.apache.org/docs/1.9.0/spec.html#schema_complex">Avro Schema Complex Types</a>
*/
public enum AvroSchemaType {
public enum AvroType {

/*
Primitive Types.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,7 +15,7 @@
import java.util.ArrayList;
import java.util.List;

public class AvroRecordFieldSchemaTypeDeserializer extends JsonDeserializer<Object> {
public class AvroTypeDeserializer extends JsonDeserializer<Object> {

@Override
final public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
Expand All @@ -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:
Expand Down
Loading

0 comments on commit 2dc488e

Please sign in to comment.