Skip to content

Commit

Permalink
refactor(schemas): split Schema to Json and AsyncAPI Schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Mar 30, 2024
1 parent 3901999 commit 09393d8
Show file tree
Hide file tree
Showing 48 changed files with 1,599 additions and 700 deletions.
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.Schema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.asyncapi.v3.schema.MultiFormatSchema;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -56,14 +56,14 @@ private Object chooseKnownPojo(JsonNode jsonNode, ObjectCodec objectCodec) throw
if (ref != null) {
return jsonParser.readValueAs(Reference.class);
} else {
return jsonParser.readValueAs(Schema.class);
return jsonParser.readValueAs(AsyncAPISchema.class);
}
}
}

private Object readAsObject(JsonNode jsonNode, ObjectCodec objectCodec) throws IOException {
try (JsonParser jsonParser = jsonNode.traverse(objectCodec)) {
return jsonParser.readValueAs(Schema.class);
return jsonParser.readValueAs(AsyncAPISchema.class);
}
}

Expand Down
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.MultiFormatSchema;
import com.asyncapi.v3.schema.Schema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
Expand Down Expand Up @@ -56,14 +56,14 @@ private Object chooseKnownPojo(JsonNode jsonNode, ObjectCodec objectCodec) throw
if (ref != null) {
return jsonParser.readValueAs(Reference.class);
} else {
return jsonParser.readValueAs(Schema.class);
return jsonParser.readValueAs(AsyncAPISchema.class);
}
}
}

private Object readAsObject(JsonNode jsonNode, ObjectCodec objectCodec) throws IOException {
try (JsonParser jsonParser = jsonNode.traverse(objectCodec)) {
return jsonParser.readValueAs(Schema.class);
return jsonParser.readValueAs(AsyncAPISchema.class);
}
}

Expand Down
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.MultiFormatSchema;
import com.asyncapi.v3.schema.Schema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
Expand All @@ -17,8 +17,8 @@

public class ComponentsSchemasDeserializer extends JsonDeserializer<Object> {

public Class<Schema> objectTypeClass() {
return Schema.class;
public Class<AsyncAPISchema> objectTypeClass() {
return AsyncAPISchema.class;
}

public Class<?> referenceClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public class Message extends ExtendableObject {
* <p>
* It MUST NOT define the protocol headers.
* <p>
* If this is a {@link com.asyncapi.v3.schema.Schema}, then the schemaFormat will be assumed to
* If this is a {@link com.asyncapi.v3.schema.AsyncAPISchema}, then the schemaFormat will be assumed to
* be "application/vnd.aai.asyncapi+json;version=asyncapi" where the version
* is equal to the AsyncAPI Version String.
* <p>
* MUST BE:
* <ul>
* <li>{@link com.asyncapi.v3.schema.Schema}</li>
* <li>{@link com.asyncapi.v3.schema.AsyncAPISchema}</li>
* <li>{@link com.asyncapi.v3.schema.MultiFormatSchema}</li>
* <li>{@link com.asyncapi.v3.Reference}</li>
* </ul>
Expand All @@ -57,12 +57,12 @@ public class Message extends ExtendableObject {
/**
* Definition of the message payload.
* <p>
* If this is a {@link com.asyncapi.v3.schema.Schema}, then the schemaFormat will be assumed to be
* If this is a {@link com.asyncapi.v3.schema.AsyncAPISchema}, then the schemaFormat will be assumed to be
* "application/vnd.aai.asyncapi+json;version=asyncapi" where the version is equal to the AsyncAPI Version String.
* <p>
* MUST BE:
* <ul>
* <li>{@link com.asyncapi.v3.schema.Schema}</li>
* <li>{@link com.asyncapi.v3.schema.AsyncAPISchema}</li>
* <li>{@link com.asyncapi.v3.schema.MultiFormatSchema}</li>
* <li>{@link com.asyncapi.v3.Reference}</li>
* </ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public class MessageTrait extends ExtendableObject {
* <p>
* It MUST NOT define the protocol headers.
* <p>
* If this is a {@link com.asyncapi.v3.schema.Schema}, then the schemaFormat will be assumed to
* If this is a {@link com.asyncapi.v3.schema.AsyncAPISchema}, then the schemaFormat will be assumed to
* be "application/vnd.aai.asyncapi+json;version=asyncapi" where the version
* is equal to the AsyncAPI Version String.
* <p>
* MUST BE:
* <ul>
* <li>{@link com.asyncapi.v3.schema.Schema}</li>
* <li>{@link com.asyncapi.v3.schema.AsyncAPISchema}</li>
* <li>{@link com.asyncapi.v3.schema.MultiFormatSchema}</li>
* <li>{@link com.asyncapi.v3.Reference}</li>
* </ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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.Schema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.asyncapi.v3.security_scheme.SecurityScheme;
import com.asyncapi.v3.ExtendableObject;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand Down Expand Up @@ -52,12 +52,12 @@ public class Components extends ExtendableObject {
/**
* An object to hold reusable Schema Object.
* <p>
* If this is a {@link Schema}, then the schemaFormat will be assumed to be "application/vnd.aai.asyncapi+json;version=asyncapi"
* If this is a {@link AsyncAPISchema}, then the schemaFormat will be assumed to be "application/vnd.aai.asyncapi+json;version=asyncapi"
* where the version is equal to the AsyncAPI Version String.
* <p>
* MUST BE:
* <ul>
* <li>{@link Schema}</li>
* <li>{@link AsyncAPISchema}</li>
* <li>{@link MultiFormatSchema}</li>
* <li>{@link Reference}</li>
* </ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.v3.binding.channel.ws;

import com.asyncapi.v3.schema.Schema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.asyncapi.v3.binding.channel.ChannelBinding;
import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -43,7 +43,7 @@ public class WebSocketsChannelBinding extends ChannelBinding {
@Nullable
@JsonProperty("query")
@JsonPropertyDescription("A Schema object containing the definitions for each query parameter. This schema MUST be of type object and have a properties key.")
private Schema query;
private AsyncAPISchema query;

/**
* A Schema object containing the definitions of the HTTP headers to use when establishing the connection.
Expand All @@ -52,7 +52,7 @@ public class WebSocketsChannelBinding extends ChannelBinding {
@Nullable
@JsonProperty("headers")
@JsonPropertyDescription("A Schema object containing the definitions of the HTTP headers to use when establishing the connection. This schema MUST be of type object and have a properties key.")
private Schema headers;
private AsyncAPISchema headers;

/**
* The version of this binding. If omitted, "latest" MUST be assumed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.v3.binding.message.anypointmq;

import com.asyncapi.v3.schema.Schema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.asyncapi.v3.binding.message.MessageBinding;
import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -31,7 +31,7 @@ public class AnypointMQMessageBinding extends MessageBinding {
@Nullable
@JsonProperty("headers")
@JsonPropertyDescription("A Schema object containing the definitions for Anypoint MQ-specific headers (so-called protocol headers). This schema MUST be of type object and have a properties key. Examples of Anypoint MQ protocol headers are messageId and messageGroupId.")
private Schema headers;
private AsyncAPISchema headers;

/**
* The version of this binding.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.v3.binding.message.http;

import com.asyncapi.v3.schema.Schema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.asyncapi.v3.binding.message.MessageBinding;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
Expand Down Expand Up @@ -30,7 +30,7 @@ public class HTTPMessageBinding extends MessageBinding {
@Nullable
@JsonProperty("headers")
@JsonPropertyDescription("A Schema object containing the definitions for each query parameter. This schema MUST be of type object and have a properties key.")
private Schema headers;
private AsyncAPISchema headers;

/**
* The version of this binding.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.v3.binding.message.kafka;

import com.asyncapi.v3.schema.Schema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.asyncapi.v3.binding.message.MessageBinding;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
Expand Down Expand Up @@ -29,7 +29,7 @@ public class KafkaMessageBinding extends MessageBinding {
@Nullable
@JsonProperty("key")
@JsonPropertyDescription("The message key.")
private Schema key;
private AsyncAPISchema key;

/**
* If a Schema Registry is used when performing this operation, tells where the id of schema is stored (e.g. header or payload).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.v3.binding.operation.http;

import com.asyncapi.v3.schema.Schema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.asyncapi.v3.binding.operation.OperationBinding;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
Expand Down Expand Up @@ -52,7 +52,7 @@ public class HTTPOperationBinding extends OperationBinding {
@Nullable
@JsonProperty("query")
@JsonPropertyDescription("A Schema object containing the definitions for each query parameter. This schema MUST be of type object and have a properties key.")
private Schema query;
private AsyncAPISchema query;

/**
* The version of this binding. If omitted, "latest" MUST be assumed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.v3.binding.operation.kafka;

import com.asyncapi.v3.schema.Schema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.asyncapi.v3.binding.operation.OperationBinding;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
Expand Down Expand Up @@ -29,15 +29,15 @@ public class KafkaOperationBinding extends OperationBinding {
@Nullable
@JsonProperty("groupId")
@JsonPropertyDescription("Id of the consumer group.")
private Schema groupId;
private AsyncAPISchema groupId;

/**
* Id of the consumer inside a consumer group.
*/
@Nullable
@JsonProperty("clientId")
@JsonPropertyDescription("Id of the consumer inside a consumer group.")
private Schema clientId;
private AsyncAPISchema clientId;

/**
* The version of this binding. If omitted, "latest" MUST be assumed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.asyncapi.v3.jackson;

import com.asyncapi.v3.schema.Schema;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
Expand All @@ -13,7 +12,9 @@
import java.util.ArrayList;
import java.util.List;

public class SchemaItemsDeserializer extends JsonDeserializer<Object> {
public abstract class SchemaItemsDeserializer<Schema> extends JsonDeserializer<Object> {

abstract public Class<Schema> schemaClass();

@Override
public Object deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
Expand All @@ -39,7 +40,7 @@ private List<Schema> readAsListOfSchemas(ArrayNode arrayNode, ObjectCodec object

private Schema readAsSchema(JsonNode jsonNode, ObjectCodec objectCodec) throws IOException {
try (JsonParser parser = jsonNode.traverse(objectCodec)) {
return parser.readValueAs(Schema.class);
return parser.readValueAs(schemaClass());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.v3.jackson.schema;

import com.asyncapi.v3.schema.Schema;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
Expand All @@ -14,7 +14,7 @@
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
public class SchemasAdditionalPropertiesDeserializer extends JsonDeserializer<Object> {
public class AsyncAPISchemaAdditionalPropertiesDeserializer extends JsonDeserializer<Object> {

@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
Expand All @@ -29,7 +29,7 @@ private Object chooseKnownPojo(JsonNode jsonNode, final ObjectCodec objectCodec)
if (jsonNode.isBoolean()) {
return jsonNode.asBoolean();
} else {
return jsonParser.readValueAs(Schema.class);
return jsonParser.readValueAs(AsyncAPISchema.class);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.asyncapi.v3.jackson.schema;

import com.asyncapi.v3.jackson.SchemaItemsDeserializer;
import com.asyncapi.v3.schema.AsyncAPISchema;
import com.fasterxml.jackson.core.JsonParser;
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 AsyncAPISchemaItemsDeserializer extends SchemaItemsDeserializer<AsyncAPISchema> {

public Class<AsyncAPISchema> schemaClass() {
return AsyncAPISchema.class;
}

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

import com.asyncapi.v3.jackson.SchemaItemsDeserializer;
import com.asyncapi.v3.schema.JsonSchema;

public class JsonSchemaItemsDeserializer extends SchemaItemsDeserializer<JsonSchema> {

public Class<JsonSchema> schemaClass() {
return JsonSchema.class;
}

}
Loading

0 comments on commit 09393d8

Please sign in to comment.