Skip to content

Commit 458906e

Browse files
committed
Update SmallRye OpenAPI and MicroProfile OpenAPI to 4.0
- OAS 3.1, normalize `type` to arrays, do not test order of health keys - Fix health schema type tests - Update Spring Web test for OAS 3.1 Signed-off-by: Michael Edgar <[email protected]>
1 parent f91f180 commit 458906e

File tree

18 files changed

+226
-291
lines changed

18 files changed

+226
-291
lines changed

bom/application/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@
4646
<microprofile-rest-client.version>4.0</microprofile-rest-client.version>
4747
<microprofile-jwt.version>2.1</microprofile-jwt.version>
4848
<microprofile-lra.version>2.0</microprofile-lra.version>
49-
<microprofile-openapi.version>3.1.2</microprofile-openapi.version>
49+
<microprofile-openapi.version>4.0.2</microprofile-openapi.version>
5050
<smallrye-common.version>2.8.0</smallrye-common.version>
5151
<smallrye-config.version>3.10.0</smallrye-config.version>
5252
<smallrye-health.version>4.1.0</smallrye-health.version>
5353
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
54-
<smallrye-open-api.version>3.13.0</smallrye-open-api.version>
54+
<smallrye-open-api.version>4.0.0</smallrye-open-api.version>
5555
<smallrye-graphql.version>2.11.0</smallrye-graphql.version>
5656
<smallrye-fault-tolerance.version>6.6.0</smallrye-fault-tolerance.version>
5757
<smallrye-jwt.version>4.6.0</smallrye-jwt.version>

extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/HealthOpenAPIFilter.java

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.List;
55
import java.util.Map;
66

7+
import org.eclipse.microprofile.openapi.OASFactory;
78
import org.eclipse.microprofile.openapi.OASFilter;
89
import org.eclipse.microprofile.openapi.models.OpenAPI;
910
import org.eclipse.microprofile.openapi.models.Operation;
@@ -13,16 +14,6 @@
1314
import org.eclipse.microprofile.openapi.models.media.Schema;
1415
import org.eclipse.microprofile.openapi.models.responses.APIResponses;
1516

16-
import io.smallrye.openapi.api.models.ComponentsImpl;
17-
import io.smallrye.openapi.api.models.OperationImpl;
18-
import io.smallrye.openapi.api.models.PathItemImpl;
19-
import io.smallrye.openapi.api.models.PathsImpl;
20-
import io.smallrye.openapi.api.models.media.ContentImpl;
21-
import io.smallrye.openapi.api.models.media.MediaTypeImpl;
22-
import io.smallrye.openapi.api.models.media.SchemaImpl;
23-
import io.smallrye.openapi.api.models.responses.APIResponseImpl;
24-
import io.smallrye.openapi.api.models.responses.APIResponsesImpl;
25-
2617
/**
2718
* Create OpenAPI entries (if configured)
2819
*/
@@ -32,37 +23,37 @@ public class HealthOpenAPIFilter implements OASFilter {
3223
private static final String HEALTH_RESPONSE_SCHEMA_NAME = "HealthResponse";
3324
private static final String HEALTH_CHECK_SCHEMA_NAME = "HealthCheck";
3425

35-
private static final Schema healthResponseSchemaDefinition = new SchemaImpl(HEALTH_RESPONSE_SCHEMA_NAME)
36-
.type(Schema.SchemaType.OBJECT)
26+
private static final Schema healthResponseSchemaDefinition = OASFactory.createSchema()
27+
.type(Collections.singletonList(Schema.SchemaType.OBJECT))
3728
.properties(Map.ofEntries(
3829

3930
Map.entry("status",
40-
new SchemaImpl()
41-
.type(Schema.SchemaType.STRING)
31+
OASFactory.createSchema()
32+
.type(Collections.singletonList(Schema.SchemaType.STRING))
4233
.enumeration(List.of("UP", "DOWN"))),
4334

4435
Map.entry("checks",
45-
new SchemaImpl()
46-
.type(Schema.SchemaType.ARRAY)
47-
.items(new SchemaImpl().ref("#/components/schemas/" + HEALTH_CHECK_SCHEMA_NAME)))));
36+
OASFactory.createSchema()
37+
.type(Collections.singletonList(Schema.SchemaType.ARRAY))
38+
.items(OASFactory.createSchema()
39+
.ref("#/components/schemas/" + HEALTH_CHECK_SCHEMA_NAME)))));
4840

49-
private static final Schema healthCheckSchemaDefinition = new SchemaImpl(HEALTH_CHECK_SCHEMA_NAME)
50-
.type(Schema.SchemaType.OBJECT)
41+
private static final Schema healthCheckSchemaDefinition = OASFactory.createSchema()
42+
.type(Collections.singletonList(Schema.SchemaType.OBJECT))
5143
.properties(Map.ofEntries(
5244

5345
Map.entry("name",
54-
new SchemaImpl()
55-
.type(Schema.SchemaType.STRING)),
46+
OASFactory.createSchema()
47+
.type(Collections.singletonList(Schema.SchemaType.STRING))),
5648

5749
Map.entry("status",
58-
new SchemaImpl()
59-
.type(Schema.SchemaType.STRING)
50+
OASFactory.createSchema()
51+
.type(Collections.singletonList(Schema.SchemaType.STRING))
6052
.enumeration(List.of("UP", "DOWN"))),
6153

6254
Map.entry("data",
63-
new SchemaImpl()
64-
.type(Schema.SchemaType.OBJECT)
65-
.nullable(Boolean.TRUE))));
55+
OASFactory.createSchema()
56+
.type(List.of(Schema.SchemaType.OBJECT, Schema.SchemaType.NULL)))));
6657

6758
private final String rootPath;
6859
private final String livenessPath;
@@ -79,13 +70,14 @@ public HealthOpenAPIFilter(String rootPath, String livenessPath, String readines
7970
@Override
8071
public void filterOpenAPI(OpenAPI openAPI) {
8172
if (openAPI.getComponents() == null) {
82-
openAPI.setComponents(new ComponentsImpl());
73+
openAPI.setComponents(OASFactory.createComponents());
8374
}
75+
8476
openAPI.getComponents().addSchema(HEALTH_RESPONSE_SCHEMA_NAME, healthResponseSchemaDefinition);
8577
openAPI.getComponents().addSchema(HEALTH_CHECK_SCHEMA_NAME, healthCheckSchemaDefinition);
8678

8779
if (openAPI.getPaths() == null) {
88-
openAPI.setPaths(new PathsImpl());
80+
openAPI.setPaths(OASFactory.createPaths());
8981
}
9082

9183
final Paths paths = openAPI.getPaths();
@@ -150,31 +142,31 @@ private PathItem createHealthEndpoint(
150142
String operationDescription,
151143
String operationId,
152144
String operationSummary) {
153-
final Content content = new ContentImpl()
145+
final Content content = OASFactory.createContent()
154146
.addMediaType(
155147
"application/json",
156-
new MediaTypeImpl()
157-
.schema(new SchemaImpl().ref("#/components/schemas/" + HEALTH_RESPONSE_SCHEMA_NAME)));
148+
OASFactory.createMediaType()
149+
.schema(OASFactory.createSchema().ref("#/components/schemas/" + HEALTH_RESPONSE_SCHEMA_NAME)));
158150

159-
final APIResponses responses = new APIResponsesImpl()
151+
final APIResponses responses = OASFactory.createAPIResponses()
160152
.addAPIResponse(
161153
"200",
162-
new APIResponseImpl().description("OK").content(content))
154+
OASFactory.createAPIResponse().description("OK").content(content))
163155
.addAPIResponse(
164156
"503",
165-
new APIResponseImpl().description("Service Unavailable").content(content))
157+
OASFactory.createAPIResponse().description("Service Unavailable").content(content))
166158
.addAPIResponse(
167159
"500",
168-
new APIResponseImpl().description("Internal Server Error").content(content));
160+
OASFactory.createAPIResponse().description("Internal Server Error").content(content));
169161

170-
final Operation getOperation = new OperationImpl()
162+
final Operation getOperation = OASFactory.createOperation()
171163
.operationId(operationId)
172164
.description(operationDescription)
173165
.tags(MICROPROFILE_HEALTH_TAG)
174166
.summary(operationSummary)
175167
.responses(responses);
176168

177-
return new PathItemImpl()
169+
return OASFactory.createPathItem()
178170
.description(endpointDescription)
179171
.summary(endpointSummary)
180172
.GET(getOperation);

extensions/smallrye-health/deployment/src/test/java/io/quarkus/smallrye/health/test/DeprecatedHealthOpenAPITest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ void testOpenApiPathAccessResource() {
4242
.body("components.schemas.HealthCheck.type", Matchers.equalTo("object"))
4343
.body("components.schemas.HealthCheck.properties.status.type", Matchers.equalTo("string"))
4444
.body("components.schemas.HealthCheck.properties.name.type", Matchers.equalTo("string"))
45-
.body("components.schemas.HealthCheck.properties.data.type", Matchers.equalTo("object"))
46-
.body("components.schemas.HealthCheck.properties.data.nullable", Matchers.is(true));
47-
45+
.body("components.schemas.HealthCheck.properties.data.type", Matchers.contains("object", "null"));
4846
}
4947

5048
}

extensions/smallrye-health/deployment/src/test/java/io/quarkus/smallrye/health/test/HealthOpenAPITest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void testOpenApiPathAccessResource() {
2828
.when().get(OPEN_API_PATH)
2929
.then()
3030
.header("Content-Type", "application/json;charset=UTF-8")
31+
3132
.body("paths", Matchers.hasKey("/q/health/ready"))
3233
.body("paths", Matchers.hasKey("/q/health/live"))
3334
.body("paths", Matchers.hasKey("/q/health/started"))
@@ -40,9 +41,7 @@ void testOpenApiPathAccessResource() {
4041
.body("components.schemas.HealthCheck.type", Matchers.equalTo("object"))
4142
.body("components.schemas.HealthCheck.properties.status.type", Matchers.equalTo("string"))
4243
.body("components.schemas.HealthCheck.properties.name.type", Matchers.equalTo("string"))
43-
.body("components.schemas.HealthCheck.properties.data.type", Matchers.equalTo("object"))
44-
.body("components.schemas.HealthCheck.properties.data.nullable", Matchers.is(true));
45-
44+
.body("components.schemas.HealthCheck.properties.data.type", Matchers.contains("object", "null"));
4645
}
4746

4847
}

0 commit comments

Comments
 (0)