Skip to content

Commit 861213f

Browse files
fjtiradogmunozfe
authored andcommitted
[Fix apache#4132] Fixing Json Schema generation (apache#4133)
Signed-off-by: fjtirado <[email protected]>
1 parent a24e197 commit 861213f

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/serverless/workflow/parser/schema/JsonSchemaImpl.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,21 @@ public class JsonSchemaImpl extends SchemaImpl {
4646

4747
private Map<String, Schema> defs;
4848

49-
private List<Schema.SchemaType> type;
50-
5149
@JsonSetter("type")
5250
public void setType(JsonNode typeNode) {
51+
List<Schema.SchemaType> types = new ArrayList<>();
5352
if (typeNode.isArray()) {
54-
List<Schema.SchemaType> types = new ArrayList<>();
5553
for (JsonNode node : typeNode) {
56-
types.add(Schema.SchemaType.valueOf(node.asText().toUpperCase()));
54+
types.add(from(node));
5755
}
58-
this.type = types;
5956
} else if (typeNode.isTextual()) {
60-
this.type = new ArrayList<>();
61-
this.type.add(Schema.SchemaType.valueOf(typeNode.asText().toUpperCase()));
57+
types.add(from(typeNode));
6258
}
59+
super.setType(types);
6360
}
6461

65-
public List<Schema.SchemaType> getType() {
66-
return type;
67-
}
68-
69-
public void setType(List<Schema.SchemaType> type) {
70-
this.type = type;
62+
private static SchemaType from(JsonNode node) {
63+
return Schema.SchemaType.valueOf(node.asText().toUpperCase());
7164
}
7265

7366
@JsonSetter("$defs")

quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/serverless/workflow/parser/schema/OpenApiModelSchemaGenerator.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,31 @@ private static String getSchemaName(String id, String suffix) {
132132
return id + suffix;
133133
}
134134

135+
private final static String PROCESS_PREFIX = "Process - ";
136+
135137
private static void processOperation(Map<String, Schema> schemas, Operation operation) {
136138
if (operation != null) {
137139
List<String> tags = operation.getTags();
138140
if (tags != null) {
139141
for (String tag : tags) {
140-
if (operation.getRequestBody() != null) {
141-
Schema schema = schemas.get(getSchemaName(tag, INPUT_SUFFIX));
142-
if (schema != null) {
143-
getMediaTypes(operation.getRequestBody().getContent()).stream().filter(OpenApiModelSchemaGenerator::isInput).forEach(mediaType -> mediaType.setSchema(schema));
142+
if (tag.startsWith(PROCESS_PREFIX)) {
143+
String processName = tag.substring(PROCESS_PREFIX.length());
144+
if (operation.getRequestBody() != null) {
145+
Schema schema = schemas.get(getSchemaName(processName, INPUT_SUFFIX));
146+
if (schema != null) {
147+
getMediaTypes(operation.getRequestBody().getContent()).stream().filter(OpenApiModelSchemaGenerator::isInput).forEach(mediaType -> mediaType.setSchema(schema));
148+
}
144149
}
145-
}
146-
if (operation.getResponses() != null && operation.getResponses().getAPIResponses() != null) {
147-
Schema schema = schemas.get(getSchemaName(tag, OUTPUT_SUFFIX));
148-
if (schema != null) {
149-
for (APIResponse response : operation.getResponses().getAPIResponses().values()) {
150-
Content content = response.getContent();
151-
if (content == null) {
152-
response.setContent(OASFactory.createContent().addMediaType("application/json", OASFactory.createMediaType().schema(schema)));
153-
} else {
154-
getMediaTypes(content).stream().filter(OpenApiModelSchemaGenerator::isOutput).forEach(mediaType -> mediaType.setSchema(schema));
150+
if (operation.getResponses() != null && operation.getResponses().getAPIResponses() != null) {
151+
Schema schema = schemas.get(getSchemaName(processName, OUTPUT_SUFFIX));
152+
if (schema != null) {
153+
for (APIResponse response : operation.getResponses().getAPIResponses().values()) {
154+
Content content = response.getContent();
155+
if (content == null) {
156+
response.setContent(OASFactory.createContent().addMediaType("application/json", OASFactory.createMediaType().schema(schema)));
157+
} else {
158+
getMediaTypes(content).stream().filter(OpenApiModelSchemaGenerator::isOutput).forEach(mediaType -> mediaType.setSchema(schema));
159+
}
155160
}
156161
}
157162
}

0 commit comments

Comments
 (0)