-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(avro schema): schemas required methods and basic tests
- Loading branch information
Showing
11 changed files
with
1,152 additions
and
11 deletions.
There are no files selected for viewing
28 changes: 27 additions & 1 deletion
28
asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroArraySchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <a href="https://avro.apache.org/docs/1.9.0/spec.html#Arrays">Arrays</a> | ||
*/ | ||
@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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 32 additions & 1 deletion
33
asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroMapSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <a href="https://avro.apache.org/docs/1.9.0/spec.html#Maps">Maps</a> | ||
*/ | ||
@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<String, Object> 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); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
asyncapi-core/src/main/java/com/asyncapi/v3/schema/avro/AvroMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, Object> metadata; | ||
|
||
@JsonAnySetter | ||
protected final void readMetadata(String name, Object value) { | ||
if (metadata == null) { | ||
metadata = new HashMap<>(); | ||
} | ||
|
||
metadata.put(name, value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.