44import java .util .List ;
55import java .util .Map ;
66
7+ import org .eclipse .microprofile .openapi .OASFactory ;
78import org .eclipse .microprofile .openapi .OASFilter ;
89import org .eclipse .microprofile .openapi .models .OpenAPI ;
910import org .eclipse .microprofile .openapi .models .Operation ;
1314import org .eclipse .microprofile .openapi .models .media .Schema ;
1415import 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 );
0 commit comments