Skip to content

Commit

Permalink
refactor(avro schema): check schemas before merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Apr 20, 2024
1 parent f7cd205 commit 2fbcbf9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.asyncapi.v3.schema.avro.v1._9_0;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Data;
Expand Down Expand Up @@ -58,19 +59,49 @@ public AvroSchema(@NotNull Builder<?, ?> builder) {
* Avro Schema type.
*/
@NotNull
@JsonProperty("type")
private String type;

/**
* A JSON integer representing the scale (optional).
* <p>
* If not specified the scale is 0.
*/
@Nullable
@JsonProperty("scale")
private Integer scale;

/*
Type: bytes, fixed
Type: bytes, fixed, decimal
*/

/**
* A JSON integer representing the (maximum) precision of decimals stored in this type (required).
*/
@Nullable
@JsonProperty("precision")
private Integer precision;

/**
* A logical type is an Avro primitive or complex type with extra attributes to represent a derived type.
* <p>
* The attribute logicalType must always be present for a logical type, and is a string with the name of one
* of the logical types listed later in this section. Other attributes may be defined for particular logical types.
* <p>
* <p>
* A logical type is always serialized using its underlying Avro type so that values are encoded in exactly the same
* way as the equivalent Avro type that does not have a logicalType attribute. Language implementations may choose to
* represent logical types with an appropriate native type, although this is not required.
* <p>
* Language implementations must ignore unknown logical types when reading, and should use the underlying Avro type.
* <p>
* If a logical type is invalid, for example a decimal with scale greater than its precision, then implementations
* should ignore the logical type and use the underlying Avro type.
*
* @see <a href="https://avro.apache.org/docs/1.9.0/spec.html#Logical+Types">Logical Types</a>
*/
@Nullable
@JsonProperty("logicalType")
private String logicalType;

public static Builder<?, ?> builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public AvroSchemaArray(@NotNull Builder builder) {
this.metadata = builder.metadata;
}

/**
* The schema of the array's items.
*/
@NotNull
@JsonProperty("items")
@JsonDeserialize(using = AvroTypeDeserializer.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public AvroSchemaEnum(@NotNull Builder builder) {
* A JSON string providing documentation to the user of this schema (optional).
*/
@Nullable
@JsonProperty("doc")
private String doc;

/**
Expand All @@ -79,6 +80,7 @@ public AvroSchemaEnum(@NotNull Builder builder) {
* Every symbol must match the regular expression [A-Za-z_][A-Za-z0-9_]* (the same requirement as for <a href="https://avro.apache.org/docs/1.9.0/spec.html#names">names</a>).
*/
@NotNull
@JsonProperty("symbols")
private List<@NotNull String> symbols = Collections.emptyList();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ public AvroSchemaFixed(@NotNull Builder builder) {
* A JSON array of strings, providing alternate names for this record (optional).
*/
@Nullable
@JsonProperty("aliases")
private List<@NotNull String> aliases;

/**
* An integer, specifying the number of bytes per value (required).
*/
@NotNull
@JsonProperty("size")
private Integer size;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.asyncapi.v3.schema.avro.v1._9_0;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -62,30 +63,35 @@ public AvroSchemaRecord(@NotNull Builder builder) {
* A JSON string providing the name of the record (required).
*/
@NotNull
@JsonProperty("name")
private String name = "";

/**
* A JSON string that qualifies the name.
*/
@Nullable
@JsonProperty("namespace")
private String namespace;

/**
* A JSON string providing documentation to the user of this schema (optional).
*/
@Nullable
@JsonProperty("doc")
private String doc;

/**
* A JSON array of strings, providing alternate names for this record (optional).
*/
@Nullable
@JsonProperty("aliases")
private List<@NotNull String> aliases;

/**
* A JSON array, listing fields (required).
*/
@NotNull
@JsonProperty("fields")
private List<@NotNull AvroSchemaRecordField> fields = Collections.emptyList();

@NotNull
Expand Down Expand Up @@ -114,9 +120,6 @@ public static class Builder extends AvroSchema.Builder<AvroSchema, Builder> {
@Nullable
private String doc;

@NotNull
private List<@NotNull String> symbols = Collections.emptyList();

@Nullable
private List<@NotNull String> aliases;

Expand All @@ -141,12 +144,6 @@ public Builder doc(@Nullable String doc) {
return this;
}

@NotNull
public Builder symbols(@NotNull List<@NotNull String> symbols) {
this.symbols = symbols;
return this;
}

@NotNull
public Builder aliases(@NotNull List<@NotNull String> aliases) {
this.aliases = aliases;
Expand Down

0 comments on commit 2fbcbf9

Please sign in to comment.