Skip to content

Commit

Permalink
Merge pull request #11 from kumuluz/feature/openapi-mp-integration
Browse files Browse the repository at this point in the history
fixed openapi mp integration
  • Loading branch information
urbim authored Nov 2, 2020
2 parents ea6d808 + 349cdc7 commit 677b8cf
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/main/java/com/kumuluz/ee/health/openapi/HealthOASFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public void filterOpenAPI(OpenAPI openAPI) {
healthStatusSchema.setType(Schema.SchemaType.STRING);
healthStatusSchema.setEnumeration(Arrays.asList(new String[]{"UP", "DOWN"}));
healthStatusSchema.setExample("UP/DOWN"); // looks better in examples
openAPI.getComponents().getSchemas().put("HealthStatus", healthStatusSchema);

Schema healthCheckSchema = new SchemaImpl();
healthCheckSchema.setType(Schema.SchemaType.OBJECT);
Expand All @@ -103,7 +102,6 @@ public void filterOpenAPI(OpenAPI openAPI) {
.nullable(true));
healthCheckSchema.setProperties(healthCheckSchemaProperties);


Schema healthResponseSchema = new SchemaImpl();
healthResponseSchema.setType(Schema.SchemaType.OBJECT);
Map<String, Schema> healthResponseSchemaProperties = new HashMap<>();
Expand All @@ -113,17 +111,26 @@ public void filterOpenAPI(OpenAPI openAPI) {
.type(Schema.SchemaType.ARRAY)
.items(healthCheckSchema));
healthResponseSchema.setProperties(healthResponseSchemaProperties);
openAPI.getComponents().getSchemas().put("HealthResponse", healthResponseSchema);

Map<String, Schema> schemas = new HashMap<>(openAPI.getComponents().getSchemas());
schemas.put("HealthStatus", healthStatusSchema);
schemas.put("HealthResponse", healthResponseSchema);

openAPI.getComponents().setSchemas(schemas);

PathItem healthPath = createHealthPath("Get information about the health of this service",
"Contains both readiness and liveness checks.");
openAPI.getPaths().addPathItem(this.servletMapping, healthPath);
PathItem healthReadyPath = createHealthPath("Get information about the readiness of this service",
null);
openAPI.getPaths().addPathItem(this.servletMapping + "/ready", healthReadyPath);
PathItem healthLivePath = createHealthPath("Get information about the liveness of this service",
null);
openAPI.getPaths().addPathItem(this.servletMapping + "/live", healthLivePath);

Map<String, PathItem> pathItems = new HashMap<>(openAPI.getPaths().getPathItems());
pathItems.put(this.servletMapping, healthPath);
pathItems.put(this.servletMapping + "/ready", healthReadyPath);
pathItems.put(this.servletMapping + "/live", healthLivePath);

openAPI.getPaths().setPathItems(pathItems);
}

private PathItem createHealthPath(String summary, String description) {
Expand Down

0 comments on commit 677b8cf

Please sign in to comment.