Skip to content

Commit 3f382f0

Browse files
authored
Upgrade data-models to support AsyncAPI 3 (#4928)
1 parent 11cfa3b commit 3f382f0

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
<skipCommitIdPlugin>true</skipCommitIdPlugin>
173173

174174
<!-- Apicurio Data Models (OpenAPI and AsyncAPI support) -->
175-
<apicurio-data-models.version>2.0.4</apicurio-data-models.version>
175+
<apicurio-data-models.version>2.1.0</apicurio-data-models.version>
176176

177177
<!-- GraphQL -->
178178
<graphql.version>22.1</graphql.version>
@@ -956,7 +956,6 @@
956956
<headerLocation>.checkstyle/java.header</headerLocation>
957957
<suppressionsLocation>.checkstyle/suppressions.xml</suppressionsLocation>
958958
<includeTestSourceDirectory>true</includeTestSourceDirectory>
959-
<encoding>UTF-8</encoding>
960959
<consoleOutput>true</consoleOutput>
961960
<failsOnError>true</failsOnError>
962961
</configuration>

schema-util/openapi/src/main/java/io/apicurio/registry/content/dereference/ReferenceRewriter.java

+33-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
import io.apicurio.datamodels.models.Node;
66
import io.apicurio.datamodels.models.Referenceable;
77
import io.apicurio.datamodels.models.asyncapi.AsyncApiMessage;
8+
import io.apicurio.datamodels.models.asyncapi.v20.AsyncApi20Message;
9+
import io.apicurio.datamodels.models.asyncapi.v21.AsyncApi21Message;
10+
import io.apicurio.datamodels.models.asyncapi.v22.AsyncApi22Message;
11+
import io.apicurio.datamodels.models.asyncapi.v23.AsyncApi23Message;
12+
import io.apicurio.datamodels.models.asyncapi.v24.AsyncApi24Message;
13+
import io.apicurio.datamodels.models.asyncapi.v25.AsyncApi25Message;
14+
import io.apicurio.datamodels.models.asyncapi.v26.AsyncApi26Message;
815
import io.apicurio.datamodels.models.visitors.AllNodeVisitor;
916

1017
import java.util.Map;
@@ -45,7 +52,7 @@ public void visitMessage(AsyncApiMessage node) {
4552

4653
// Note: for now we have special handling of the payload because it's not yet fully modeled in the
4754
// apicurio-data-models library.
48-
JsonNode payload = node.getPayload();
55+
JsonNode payload = getPayload(node);
4956
if (payload != null && payload.hasNonNull("$ref")) {
5057
String $ref = payload.get("$ref").asText();
5158
if (referenceUrls.containsKey($ref)) {
@@ -54,4 +61,29 @@ public void visitMessage(AsyncApiMessage node) {
5461
}
5562
}
5663

64+
private JsonNode getPayload(AsyncApiMessage node) {
65+
if (node instanceof AsyncApi20Message) {
66+
return ((AsyncApi20Message) node).getPayload();
67+
}
68+
if (node instanceof AsyncApi21Message) {
69+
return ((AsyncApi21Message) node).getPayload();
70+
}
71+
if (node instanceof AsyncApi22Message) {
72+
return ((AsyncApi22Message) node).getPayload();
73+
}
74+
if (node instanceof AsyncApi23Message) {
75+
return ((AsyncApi23Message) node).getPayload();
76+
}
77+
if (node instanceof AsyncApi24Message) {
78+
return ((AsyncApi24Message) node).getPayload();
79+
}
80+
if (node instanceof AsyncApi25Message) {
81+
return ((AsyncApi25Message) node).getPayload();
82+
}
83+
if (node instanceof AsyncApi26Message) {
84+
return ((AsyncApi26Message) node).getPayload();
85+
}
86+
return null;
87+
}
88+
5789
}

schema-util/openapi/src/main/java/io/apicurio/registry/content/refs/AbstractDataModelsReferenceFinder.java

+33-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
import io.apicurio.datamodels.models.Node;
99
import io.apicurio.datamodels.models.Referenceable;
1010
import io.apicurio.datamodels.models.asyncapi.AsyncApiMessage;
11+
import io.apicurio.datamodels.models.asyncapi.v20.AsyncApi20Message;
12+
import io.apicurio.datamodels.models.asyncapi.v21.AsyncApi21Message;
13+
import io.apicurio.datamodels.models.asyncapi.v22.AsyncApi22Message;
14+
import io.apicurio.datamodels.models.asyncapi.v23.AsyncApi23Message;
15+
import io.apicurio.datamodels.models.asyncapi.v24.AsyncApi24Message;
16+
import io.apicurio.datamodels.models.asyncapi.v25.AsyncApi25Message;
17+
import io.apicurio.datamodels.models.asyncapi.v26.AsyncApi26Message;
1118
import io.apicurio.datamodels.models.visitors.AllNodeVisitor;
1219
import io.apicurio.registry.content.TypedContent;
1320
import io.apicurio.registry.content.util.ContentTypeUtil;
@@ -72,14 +79,39 @@ protected void visitNode(Node node) {
7279
public void visitMessage(AsyncApiMessage node) {
7380
// Note: special handling of message payloads because data-models doesn't fully model the payload
7481
// yet.
75-
JsonNode payload = node.getPayload();
82+
JsonNode payload = getPayload(node);
7683
if (payload != null && payload.has("$ref") && !payload.get("$ref").isNull()) {
7784
String ref = payload.get("$ref").asText();
7885
allReferences.add(ref);
7986
}
8087
super.visitMessage(node);
8188
}
8289

90+
private JsonNode getPayload(AsyncApiMessage node) {
91+
if (node instanceof AsyncApi20Message) {
92+
return ((AsyncApi20Message) node).getPayload();
93+
}
94+
if (node instanceof AsyncApi21Message) {
95+
return ((AsyncApi21Message) node).getPayload();
96+
}
97+
if (node instanceof AsyncApi22Message) {
98+
return ((AsyncApi22Message) node).getPayload();
99+
}
100+
if (node instanceof AsyncApi23Message) {
101+
return ((AsyncApi23Message) node).getPayload();
102+
}
103+
if (node instanceof AsyncApi24Message) {
104+
return ((AsyncApi24Message) node).getPayload();
105+
}
106+
if (node instanceof AsyncApi25Message) {
107+
return ((AsyncApi25Message) node).getPayload();
108+
}
109+
if (node instanceof AsyncApi26Message) {
110+
return ((AsyncApi26Message) node).getPayload();
111+
}
112+
return null;
113+
}
114+
83115
}
84116

85117
}

0 commit comments

Comments
 (0)