Skip to content

Commit a366a32

Browse files
authored
Merge pull request #127 from gmunozfe/9.104.x-prod_4132
[9.104.x-prod][Fix apache#4132] Fixing Json Schema generation (apache#4133)
2 parents 6d3d9ca + 861213f commit a366a32

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
@@ -134,26 +134,31 @@ private static String getSchemaName(String id, String suffix) {
134134
return id + suffix;
135135
}
136136

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

0 commit comments

Comments
 (0)