Skip to content

Commit

Permalink
Merge pull request #20259 from MikeEdgar/smallrye-open-api-897
Browse files Browse the repository at this point in the history
Align OpenAPI Health model to MP Health 3.x (state -> status)
  • Loading branch information
phillip-kruger authored Sep 20, 2021
2 parents ac34af1 + fd4e8d3 commit e5b4d79
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*/
public class HealthOpenAPIFilter implements OASFilter {
private static final List<String> MICROPROFILE_HEALTH_TAG = Collections.singletonList("MicroProfile Health");
private static final String SCHEMA_HEALTH_RESPONSE = "HealthCheckResponse";
private static final String SCHEMA_HEALTH_STATUS = "HealthCheckStatus";

private final String rootPath;
private final String livenessPath;
Expand All @@ -50,8 +52,8 @@ public void filterOpenAPI(OpenAPI openAPI) {
if (openAPI.getComponents() == null) {
openAPI.setComponents(new ComponentsImpl());
}
openAPI.getComponents().addSchema("HealthCheckResponse", createHealthCheckResponse());
openAPI.getComponents().addSchema("State", createState());
openAPI.getComponents().addSchema(SCHEMA_HEALTH_RESPONSE, createHealthCheckResponse());
openAPI.getComponents().addSchema(SCHEMA_HEALTH_STATUS, createHealthCheckStatus());

if (openAPI.getPaths() == null) {
openAPI.setPaths(new PathsImpl());
Expand Down Expand Up @@ -170,7 +172,7 @@ private Content createContent() {

private MediaType createMediaType() {
MediaType mediaType = new MediaTypeImpl();
mediaType.setSchema(new SchemaImpl().ref("#/components/schemas/HealthCheckResponse"));
mediaType.setSchema(new SchemaImpl().ref("#/components/schemas/" + SCHEMA_HEALTH_RESPONSE));
return mediaType;
}

Expand All @@ -183,13 +185,13 @@ private MediaType createMediaType() {
* nullable: true
* name:
* type: string
* state:
* $ref: '#/components/schemas/State'
*
* status:
* $ref: '#/components/schemas/HealthCheckStatus'
*
* @return Schema representing HealthCheckResponse
*/
private Schema createHealthCheckResponse() {
Schema schema = new SchemaImpl("HealthCheckResponse");
Schema schema = new SchemaImpl(SCHEMA_HEALTH_RESPONSE);
schema.setType(Schema.SchemaType.OBJECT);
schema.setProperties(createProperties());
return schema;
Expand All @@ -199,7 +201,7 @@ private Map<String, Schema> createProperties() {
Map<String, Schema> map = new HashMap<>();
map.put("data", createData());
map.put("name", createName());
map.put("state", new SchemaImpl().ref("#/components/schemas/State"));
map.put("status", new SchemaImpl().ref("#/components/schemas/" + SCHEMA_HEALTH_STATUS));
return map;
}

Expand All @@ -217,16 +219,16 @@ private Schema createName() {
}

/**
* State:
* HealthCheckStatus:
* enum:
* - DOWN
* - UP
* type: string
*
* @return Schema representing State
*
* @return Schema representing Status
*/
private Schema createState() {
Schema schema = new SchemaImpl("State");
private Schema createHealthCheckStatus() {
Schema schema = new SchemaImpl(SCHEMA_HEALTH_STATUS);
schema.setEnumeration(createStateEnumValues());
schema.setType(Schema.SchemaType.STRING);
return schema;
Expand Down

0 comments on commit e5b4d79

Please sign in to comment.