Skip to content

Commit

Permalink
feat(schemaFormat): support AsyncAPI, OpenAPI and Json Schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Apr 10, 2024
1 parent 5e7e58b commit 38b8219
Show file tree
Hide file tree
Showing 200 changed files with 9,564 additions and 488 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.asyncapi.v3.Reference;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.asyncapi.v3.schema.MultiFormatSchema;
import com.asyncapi.v3.schema.multiformat.MultiFormatSchema;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.asyncapi.v3._0_0.jackson.model.channel.message;

import com.asyncapi.v3.Reference;
import com.asyncapi.v3.schema.MultiFormatSchema;
import com.asyncapi.v3.schema.multiformat.MultiFormatSchema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.asyncapi.v3._0_0.jackson.model.component;

import com.asyncapi.v3.Reference;
import com.asyncapi.v3.schema.MultiFormatSchema;
import com.asyncapi.v3.schema.multiformat.MultiFormatSchema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.asyncapi.v3._0_0.model.ExternalDocumentation;
import com.asyncapi.v3._0_0.model.Tag;
import com.asyncapi.v3.jackson.binding.message.MessageBindingsDeserializer;
import com.asyncapi.v3.schema.multiformat.MultiFormatSchema;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.*;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class Message extends ExtendableObject {
* MUST BE:
* <ul>
* <li>{@link com.asyncapi.v3.schema.AsyncAPISchema}</li>
* <li>{@link com.asyncapi.v3.schema.MultiFormatSchema}</li>
* <li>{@link MultiFormatSchema}</li>
* <li>{@link com.asyncapi.v3.Reference}</li>
* </ul>
*/
Expand All @@ -63,7 +64,7 @@ public class Message extends ExtendableObject {
* MUST BE:
* <ul>
* <li>{@link com.asyncapi.v3.schema.AsyncAPISchema}</li>
* <li>{@link com.asyncapi.v3.schema.MultiFormatSchema}</li>
* <li>{@link MultiFormatSchema}</li>
* <li>{@link com.asyncapi.v3.Reference}</li>
* </ul>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.asyncapi.v3._0_0.model.ExternalDocumentation;
import com.asyncapi.v3._0_0.model.Tag;
import com.asyncapi.v3.jackson.binding.message.MessageBindingsDeserializer;
import com.asyncapi.v3.schema.multiformat.MultiFormatSchema;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.*;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class MessageTrait extends ExtendableObject {
* MUST BE:
* <ul>
* <li>{@link com.asyncapi.v3.schema.AsyncAPISchema}</li>
* <li>{@link com.asyncapi.v3.schema.MultiFormatSchema}</li>
* <li>{@link MultiFormatSchema}</li>
* <li>{@link com.asyncapi.v3.Reference}</li>
* </ul>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.asyncapi.v3.jackson.binding.message.MessageBindingsDeserializer;
import com.asyncapi.v3.jackson.binding.operation.OperationBindingsDeserializer;
import com.asyncapi.v3.jackson.binding.server.ServerBindingsDeserializer;
import com.asyncapi.v3.schema.MultiFormatSchema;
import com.asyncapi.v3.schema.multiformat.MultiFormatSchema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.asyncapi.v3.security_scheme.SecurityScheme;
import com.asyncapi.v3.ExtendableObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.asyncapi.v3.jackson.schema.AsyncAPISchemaAdditionalPropertiesDeserializer;
import com.asyncapi.v3.jackson.schema.AsyncAPISchemaAnyValueDeserializer;
import com.asyncapi.v3.jackson.schema.AsyncAPISchemaItemsDeserializer;
import com.asyncapi.v3.schema.multiformat.MultiFormatSchema;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.asyncapi.v3.schema.multiformat;

import com.asyncapi.v3.schema.AsyncAPISchema;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* The Multi Format Schema Object represents a schema definition. It differs from the {@link AsyncAPISchema} in that it supports
* multiple schema formats or languages (e.g., JSON Schema, Avro, etc.).
*
* @see <a href="https://www.asyncapi.com/docs/reference/specification/v3.0.0#multiFormatSchemaObject">Multi Format Schema</a>
* @see <a href="https://www.asyncapi.com/docs/reference/specification/v3.0.0#schemaObject">Schema</a>
* @author Pavel Bodiachevskii
* @version 3.0.0
*/
@EqualsAndHashCode(callSuper = true)
public class AsyncAPIFormatSchema extends MultiFormatSchema<AsyncAPISchema> {

public AsyncAPIFormatSchema(@NotNull AsyncAPISchema schema) {
super(schema);
}

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public AsyncAPIFormatSchema(
@JsonProperty("schemaFormat") @Nullable String schemaFormat,
@JsonProperty("schema") @NotNull AsyncAPISchema schema
) {
super(schemaFormat(schemaFormat), schema);
}

@Override
public void setSchema(@NotNull AsyncAPISchema schema) {
super.setSchema(schema);
}

@NotNull
public AsyncAPISchema getSchema() {
return super.getSchema();
}

@NotNull
private static String schemaFormat(@Nullable String schemaFormat) {
if (schemaFormat == null || schemaFormat.isEmpty()) {
return "application/vnd.aai.asyncapi+json;version=3.0.0";
}

return schemaFormat;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.asyncapi.v3.schema.multiformat;

import com.asyncapi.v3.schema.AsyncAPISchema;
import com.asyncapi.v3.schema.JsonSchema;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

/**
* The Multi Format Schema Object represents a schema definition. It differs from the {@link AsyncAPISchema} in that it supports
* multiple schema formats or languages (e.g., JSON Schema, Avro, etc.).
*
* @see <a href="https://www.asyncapi.com/docs/reference/specification/v3.0.0#multiFormatSchemaObject">Multi Format Schema</a>
* @see <a href="https://www.asyncapi.com/docs/reference/specification/v3.0.0#schemaObject">Schema</a>
* @author Pavel Bodiachevskii
* @version 3.0.0
*/
@EqualsAndHashCode(callSuper = true)
public class JsonFormatSchema extends MultiFormatSchema<JsonSchema> {

public JsonFormatSchema(@NotNull JsonSchema schema) {
super("application/schema+json;version=draft-07", schema);
}

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public JsonFormatSchema(
@JsonProperty("schemaFormat") @NotNull String schemaFormat,
@JsonProperty("schema") @NotNull JsonSchema schema
) {
super(schemaFormat, schema);
}

@Override
public void setSchema(@NotNull JsonSchema schema) {
super.setSchema(schema);
}

@NotNull
public JsonSchema getSchema() {
return super.getSchema();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.asyncapi.v3.schema.multiformat;

import com.asyncapi.v3.ExtendableObject;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

/**
* The Multi Format Schema Object represents a schema definition. It differs from the {@link AsyncAPISchema} in that it supports
* multiple schema formats or languages (e.g., JSON Schema, Avro, etc.).
*
* @see <a href="https://www.asyncapi.com/docs/reference/specification/v3.0.0#multiFormatSchemaObject">Multi Format Schema</a>
* @see <a href="https://www.asyncapi.com/docs/reference/specification/v3.0.0#schemaObject">Schema</a>
* @author Pavel Bodiachevskii
* @version 3.0.0
*/
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
defaultImpl = AsyncAPIFormatSchema.class,
property = "schemaFormat",
visible = true
)
@JsonSubTypes({
@JsonSubTypes.Type(value = JsonFormatSchema.class, names = {
"application/schema+json;version=draft-07",
"application/schema+yaml;version=draft-07"
}),
@JsonSubTypes.Type(value = OpenAPIFormatSchema.class, names = {
"application/vnd.oai.openapi;version=3.0.0",
"application/vnd.oai.openapi+json;version=3.0.0",
"application/vnd.oai.openapi+yaml;version=3.0.0"
}),
@JsonSubTypes.Type(value = AsyncAPIFormatSchema.class, names = {
"application/vnd.aai.asyncapi;version=2.0.0",
"application/vnd.aai.asyncapi+json;version=2.0.0",
"application/vnd.aai.asyncapi+yaml;version=2.0.0",
"application/vnd.aai.asyncapi;version=2.1.0",
"application/vnd.aai.asyncapi+json;version=2.1.0",
"application/vnd.aai.asyncapi+yaml;version=2.1.0",
"application/vnd.aai.asyncapi;version=2.2.0",
"application/vnd.aai.asyncapi+json;version=2.2.0",
"application/vnd.aai.asyncapi+yaml;version=2.2.0",
"application/vnd.aai.asyncapi;version=2.3.0",
"application/vnd.aai.asyncapi+json;version=2.3.0",
"application/vnd.aai.asyncapi+yaml;version=2.3.0",
"application/vnd.aai.asyncapi;version=2.4.0",
"application/vnd.aai.asyncapi+json;version=2.4.0",
"application/vnd.aai.asyncapi+yaml;version=2.4.0",
"application/vnd.aai.asyncapi;version=2.5.0",
"application/vnd.aai.asyncapi+json;version=2.5.0",
"application/vnd.aai.asyncapi+yaml;version=2.5.0",
"application/vnd.aai.asyncapi;version=2.6.0",
"application/vnd.aai.asyncapi+json;version=2.6.0",
"application/vnd.aai.asyncapi+yaml;version=2.6.0",
"application/vnd.aai.asyncapi;version=3.0.0",
"application/vnd.aai.asyncapi+json;version=3.0.0",
"application/vnd.aai.asyncapi+yaml;version=3.0.0"
})
})
@EqualsAndHashCode(callSuper = true)
public class MultiFormatSchema<Schema> extends ExtendableObject {

public MultiFormatSchema(@NotNull Schema schema) {
this.schemaFormat = "application/vnd.aai.asyncapi+json;version=3.0.0";
this.schema = schema;
}

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public MultiFormatSchema(
@JsonProperty("schemaFormat") @NotNull String schemaFormat,
@JsonProperty("schema") @NotNull Schema schema
) {
this.schemaFormat = schemaFormat;
this.schema = schema;
}

/**
* <b>Required</b>.
* <p>
* A string containing the name of the schema format that is used to define the information.
* <p>
* If schemaFormat is missing, it MUST default to application/vnd.aai.asyncapi+json;version={{asyncapi}}
* where {{asyncapi}} matches the {@link com.asyncapi.v3._0_0.model.AsyncAPI#getAsyncapi()} version string.
* <p>
* In such a case, this would make the Multi Format Schema Object equivalent to the {@link AsyncAPISchema}.
* <p>
* When using {@link com.asyncapi.v3.Reference} within the {@link #getSchema()}, the schemaFormat of the resource being referenced MUST match
* the schemaFormat of the {@link #getSchema()} that contains the initial reference.
* <p>
* For example, if you reference Avro schema, then schemaFormat of referencing resource and the resource being reference MUST match.
* <p>
* <p>
* Check out the supported schema formats table for more information.
* Custom values are allowed but their implementation is OPTIONAL.
* A custom value MUST NOT refer to one of the schema formats listed in the table.
* <p>
* <p>
* When using {@link com.asyncapi.v3.Reference} within the {@link #getSchema()}, the schemaFormat of the referenced resource MUST
* match the schemaFormat of the schema containing the reference.
*
* @see <a href="https://www.asyncapi.com/docs/reference/specification/v3.0.0#multiFormatSchemaFormatTable">Schema formats table</a>
*/
@NotNull
@JsonProperty("schemaFormat")
private String schemaFormat;

public void setSchemaFormat(@NotNull String schemaFormat) {
this.schemaFormat = schemaFormat;
}

@NotNull
public String getSchemaFormat() {
return schemaFormat;
}

/**
* <b>Required</b>.
* <p>
* Definition of the message payload.
* <p>
* It can be of any type but defaults to {@link AsyncAPISchema}.
* <p>
* It MUST match the schema format defined in {@link #getSchemaFormat()}, including the encoding type. E.g., Avro should be
* inlined as either a YAML or JSON object instead of as a string to be parsed as YAML or JSON. Non-JSON-based
* schemas (e.g., Protobuf or XSD) MUST be inlined as a string.
*/
@NotNull
@JsonProperty("schema")
private Schema schema;

public void setSchema(@NotNull Schema schema) {
this.schema = schema;
}

@NotNull
public Schema getSchema() {
return schema;
}

}
Loading

0 comments on commit 38b8219

Please sign in to comment.