-
-
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.
Merge pull request #10 from Pakisan/feat/3.0.0-preview
feat: 3.0.0 preview
- Loading branch information
Showing
812 changed files
with
104,687 additions
and
252 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
asyncapi-core/src/main/java/com/asyncapi/v3/ExtendableObject.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,43 @@ | ||
package com.asyncapi.v3; | ||
|
||
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; | ||
import java.util.regex.Pattern; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonIgnoreProperties({"extensionFields"}) | ||
public class ExtendableObject { | ||
|
||
private static final Pattern extensionPropertyNamePattern = Pattern.compile("^x-[\\w\\d\\-\\_]+$"); | ||
|
||
/** | ||
* Extension fields in the form x-extension-field-name for the exposed API. | ||
*/ | ||
@Nullable | ||
@JsonAnyGetter | ||
protected Map<String, Object> extensionFields; | ||
|
||
@JsonAnySetter | ||
protected final void readExtensionProperty(String name, Object value) { | ||
if (extensionPropertyNamePattern.matcher(name).matches()) { | ||
if (extensionFields == null) { | ||
extensionFields = new HashMap<>(); | ||
} | ||
|
||
extensionFields.put(name, value); | ||
} else { | ||
throw new IllegalArgumentException(String.format("\"%s\" is not valid extension property", name)); | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
asyncapi-core/src/main/java/com/asyncapi/v3/Reference.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,38 @@ | ||
package com.asyncapi.v3; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* A simple object to allow referencing other components in the specification, internally and externally. | ||
* <p> | ||
* The Reference Object is defined by <a href="https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03">JSON Reference</a> and follows the same structure, behavior and rules. | ||
* A JSON Reference SHALL only be used to refer to a schema that is formatted in either JSON or YAML. | ||
* In the case of a YAML-formatted Schema, the JSON Reference SHALL be applied to the JSON representation of | ||
* that schema. The JSON representation SHALL be made by applying the conversion described <a href="https://www.asyncapi.com/docs/reference/specification/v2.6.0#format">here</a>. | ||
* <p> | ||
* For this specification, reference resolution is done as defined by the JSON Reference specification and not by | ||
* the JSON Schema specification. | ||
* | ||
* @version 3.0.0 | ||
* @see <a href="https://www.asyncapi.com/docs/reference/specification/v3.0.0-next-major-spec.14#referenceObject">Reference</a> | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Reference { | ||
|
||
/** | ||
* Required. | ||
* <p> | ||
* The reference string. | ||
*/ | ||
@NotNull | ||
@JsonProperty(value = "$ref") | ||
private String ref = ""; | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...e/src/main/java/com/asyncapi/v3/_0_0/jackson/model/ExternalDocumentationDeserializer.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,23 @@ | ||
package com.asyncapi.v3._0_0.jackson.model; | ||
|
||
import com.asyncapi.v3.Reference; | ||
import com.asyncapi.v3._0_0.model.ExternalDocumentation; | ||
import com.asyncapi.v3.jackson.ReferenceOrObjectDeserializer; | ||
|
||
/** | ||
* Deserializes external documentation. | ||
* | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
public class ExternalDocumentationDeserializer extends ReferenceOrObjectDeserializer<ExternalDocumentation> { | ||
|
||
@Override | ||
public Class<ExternalDocumentation> objectTypeClass() { | ||
return ExternalDocumentation.class; | ||
} | ||
|
||
public Class<?> referenceClass() { | ||
return Reference.class; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
asyncapi-core/src/main/java/com/asyncapi/v3/_0_0/jackson/model/TagsDeserializer.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,24 @@ | ||
package com.asyncapi.v3._0_0.jackson.model; | ||
|
||
import com.asyncapi.v3.Reference; | ||
import com.asyncapi.v3._0_0.model.Tag; | ||
import com.asyncapi.v3.jackson.ListOfReferencesOrObjectsDeserializer; | ||
|
||
/** | ||
* Deserializes tags. | ||
* | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
public class TagsDeserializer extends ListOfReferencesOrObjectsDeserializer<Tag> { | ||
|
||
@Override | ||
public Class<Tag> objectTypeClass() { | ||
return Tag.class; | ||
} | ||
|
||
@Override | ||
public Class<?> referenceClass() { | ||
return Reference.class; | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...c/main/java/com/asyncapi/v3/_0_0/jackson/model/channel/ChannelParametersDeserializer.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,25 @@ | ||
package com.asyncapi.v3._0_0.jackson.model.channel; | ||
|
||
import com.asyncapi.v3.Reference; | ||
import com.asyncapi.v3._0_0.model.channel.Parameter; | ||
import com.asyncapi.v3.jackson.MapOfReferencesOrObjectsDeserializer; | ||
|
||
/** | ||
* Serializes {@link com.asyncapi.v3._0_0.model.channel.Parameter} variables map. | ||
* | ||
* @version 3.0.0 | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
public class ChannelParametersDeserializer extends MapOfReferencesOrObjectsDeserializer<Parameter> { | ||
|
||
@Override | ||
public Class<Parameter> objectTypeClass() { | ||
return Parameter.class; | ||
} | ||
|
||
@Override | ||
public Class<?> referenceClass() { | ||
return Reference.class; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...i-core/src/main/java/com/asyncapi/v3/_0_0/jackson/model/channel/ChannelsDeserializer.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,24 @@ | ||
package com.asyncapi.v3._0_0.jackson.model.channel; | ||
|
||
import com.asyncapi.v3.Reference; | ||
import com.asyncapi.v3._0_0.model.channel.Channel; | ||
import com.asyncapi.v3.jackson.MapOfReferencesOrObjectsDeserializer; | ||
|
||
/** | ||
* Serializes component channels map. | ||
* | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
public class ChannelsDeserializer extends MapOfReferencesOrObjectsDeserializer<Channel> { | ||
|
||
@Override | ||
public Class<Channel> objectTypeClass() { | ||
return Channel.class; | ||
} | ||
|
||
@Override | ||
public Class<?> referenceClass() { | ||
return Reference.class; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
.../com/asyncapi/v3/_0_0/jackson/model/channel/message/MessageCorrelationIdDeserializer.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,23 @@ | ||
package com.asyncapi.v3._0_0.jackson.model.channel.message; | ||
|
||
import com.asyncapi.v3.Reference; | ||
import com.asyncapi.v3._0_0.model.channel.message.CorrelationId; | ||
import com.asyncapi.v3.jackson.ReferenceOrObjectDeserializer; | ||
|
||
/** | ||
* Serializes message correlation id. | ||
* | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
public class MessageCorrelationIdDeserializer extends ReferenceOrObjectDeserializer<CorrelationId> { | ||
|
||
@Override | ||
public Class<CorrelationId> objectTypeClass() { | ||
return CorrelationId.class; | ||
} | ||
|
||
public Class<?> referenceClass() { | ||
return Reference.class; | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
...n/java/com/asyncapi/v3/_0_0/jackson/model/channel/message/MessageHeadersDeserializer.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,77 @@ | ||
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.MultiFormatSchema; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
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.exc.UnrecognizedPropertyException; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Serializes message traits list. | ||
* | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
public class MessageHeadersDeserializer extends JsonDeserializer<Object> { | ||
|
||
@Override | ||
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
ObjectCodec objectCodec = p.getCodec(); | ||
JsonNode node = objectCodec.readTree(p); | ||
|
||
/* | ||
Problem: | ||
Both, Reference class and Schema class have $ref field. | ||
So, this is only reason why I receive next exception: | ||
"com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: | ||
Unrecognized field "title" (class com.asyncapi.v2._6_0.model.Reference), | ||
not marked as ignorable (one known property: "$ref"])" | ||
in case when Schema contains $ref. | ||
Solution: | ||
Try to deserialize reference. In case of exception, try to deserialize it as given ObjectType. In case of | ||
one more exception, throw it. | ||
TODO: Think how to improve. | ||
*/ | ||
try { | ||
return chooseKnownPojo(node, objectCodec); | ||
} catch (UnrecognizedPropertyException unrecognizedPropertyException) { | ||
return readAsObject(node, objectCodec); | ||
} | ||
} | ||
|
||
private Object chooseKnownPojo(JsonNode jsonNode, ObjectCodec objectCodec) throws IOException { | ||
JsonNode ref = jsonNode.get("$ref"); | ||
try (JsonParser jsonParser = jsonNode.traverse(objectCodec)) { | ||
if (isMultiFormatSchema(jsonNode)) { | ||
return jsonParser.readValueAs(MultiFormatSchema.class); | ||
} | ||
|
||
if (ref != null) { | ||
return jsonParser.readValueAs(Reference.class); | ||
} else { | ||
return jsonParser.readValueAs(Schema.class); | ||
} | ||
} | ||
} | ||
|
||
private Object readAsObject(JsonNode jsonNode, ObjectCodec objectCodec) throws IOException { | ||
try (JsonParser jsonParser = jsonNode.traverse(objectCodec)) { | ||
return jsonParser.readValueAs(Schema.class); | ||
} | ||
} | ||
|
||
private boolean isMultiFormatSchema(@NotNull JsonNode jsonNode) { | ||
JsonNode schemaFormat = jsonNode.get("schemaFormat"); | ||
JsonNode schema = jsonNode.get("schema"); | ||
|
||
return (schemaFormat != null) && (schema != null); | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
...n/java/com/asyncapi/v3/_0_0/jackson/model/channel/message/MessagePayloadDeserializer.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,77 @@ | ||
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.Schema; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
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.exc.UnrecognizedPropertyException; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Serializes message traits list. | ||
* | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
public class MessagePayloadDeserializer extends JsonDeserializer<Object> { | ||
|
||
@Override | ||
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
ObjectCodec objectCodec = p.getCodec(); | ||
JsonNode node = objectCodec.readTree(p); | ||
|
||
/* | ||
Problem: | ||
Both, Reference class and Schema class have $ref field. | ||
So, this is only reason why I receive next exception: | ||
"com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: | ||
Unrecognized field "title" (class com.asyncapi.v2._6_0.model.Reference), | ||
not marked as ignorable (one known property: "$ref"])" | ||
in case when Schema contains $ref. | ||
Solution: | ||
Try to deserialize reference. In case of exception, try to deserialize it as given ObjectType. In case of | ||
one more exception, throw it. | ||
TODO: Think how to improve. | ||
*/ | ||
try { | ||
return chooseKnownPojo(node, objectCodec); | ||
} catch (UnrecognizedPropertyException unrecognizedPropertyException) { | ||
return readAsObject(node, objectCodec); | ||
} | ||
} | ||
|
||
private Object chooseKnownPojo(JsonNode jsonNode, ObjectCodec objectCodec) throws IOException { | ||
JsonNode ref = jsonNode.get("$ref"); | ||
try (JsonParser jsonParser = jsonNode.traverse(objectCodec)) { | ||
if (isMultiFormatSchema(jsonNode)) { | ||
return jsonParser.readValueAs(MultiFormatSchema.class); | ||
} | ||
|
||
if (ref != null) { | ||
return jsonParser.readValueAs(Reference.class); | ||
} else { | ||
return jsonParser.readValueAs(Schema.class); | ||
} | ||
} | ||
} | ||
|
||
private Object readAsObject(JsonNode jsonNode, ObjectCodec objectCodec) throws IOException { | ||
try (JsonParser jsonParser = jsonNode.traverse(objectCodec)) { | ||
return jsonParser.readValueAs(Schema.class); | ||
} | ||
} | ||
|
||
private boolean isMultiFormatSchema(@NotNull JsonNode jsonNode) { | ||
JsonNode schemaFormat = jsonNode.get("schemaFormat"); | ||
JsonNode schema = jsonNode.get("schema"); | ||
|
||
return (schemaFormat != null) && (schema != null); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...in/java/com/asyncapi/v3/_0_0/jackson/model/channel/message/MessageTraitsDeserializer.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,24 @@ | ||
package com.asyncapi.v3._0_0.jackson.model.channel.message; | ||
|
||
import com.asyncapi.v3.Reference; | ||
import com.asyncapi.v3._0_0.model.channel.message.MessageTrait; | ||
import com.asyncapi.v3.jackson.ListOfReferencesOrObjectsDeserializer; | ||
|
||
/** | ||
* Deserializes message traits. | ||
* | ||
* @author Pavel Bodiachevskii | ||
*/ | ||
public class MessageTraitsDeserializer extends ListOfReferencesOrObjectsDeserializer<MessageTrait> { | ||
|
||
@Override | ||
public Class<MessageTrait> objectTypeClass() { | ||
return MessageTrait.class; | ||
} | ||
|
||
@Override | ||
public Class<?> referenceClass() { | ||
return Reference.class; | ||
} | ||
|
||
} |
Oops, something went wrong.