Search in sources :

Example 1 with OpenApiService

use of fish.payara.microprofile.openapi.impl.OpenApiService in project Payara by payara.

the class OpenApiResource method getResponse.

@GET
@Produces({ APPLICATION_YAML, APPLICATION_JSON })
public Response getResponse(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException {
    OpenApiService openApiService = OpenApiService.getInstance();
    // If the server is disabled, throw an error
    if (!openApiService.isEnabled()) {
        response.sendError(FORBIDDEN.getStatusCode(), "MicroProfile OpenAPI Service is disabled.");
        return Response.status(FORBIDDEN).build();
    }
    // Get the OpenAPI document
    OpenAPI document = null;
    try {
        document = openApiService.getDocument();
    } catch (OpenAPIBuildException | IOException ex) {
        LOGGER.log(WARNING, "OpenAPI document creation failed.", ex);
    }
    // If there are none, return an empty OpenAPI document
    if (document == null) {
        LOGGER.info("No OpenAPI document found.");
        OpenAPI result = new BaseProcessor(new ArrayList<>()).process(new OpenAPIImpl(), null);
        return Response.status(Status.NOT_FOUND).entity(result).build();
    }
    // Return the document
    return Response.ok(document).build();
}
Also used : OpenAPIImpl(fish.payara.microprofile.openapi.impl.model.OpenAPIImpl) OpenApiService(fish.payara.microprofile.openapi.impl.OpenApiService) ArrayList(java.util.ArrayList) OpenAPIBuildException(fish.payara.microprofile.openapi.api.OpenAPIBuildException) IOException(java.io.IOException) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) BaseProcessor(fish.payara.microprofile.openapi.impl.processor.BaseProcessor) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with OpenApiService

use of fish.payara.microprofile.openapi.impl.OpenApiService in project Payara by payara.

the class CorsHeadersFilter method filter.

@Override
public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException {
    OpenApiService openApiService = OpenApiService.getInstance();
    if (openApiService.isEnabled() && openApiService.withCorsHeaders()) {
        MultivaluedMap<String, Object> headers = response.getHeaders();
        headers.add("Access-Control-Allow-Origin", "*");
        headers.add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
        headers.add("Access-Control-Allow-Credentials", "true");
        headers.add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
    }
}
Also used : OpenApiService(fish.payara.microprofile.openapi.impl.OpenApiService)

Aggregations

OpenApiService (fish.payara.microprofile.openapi.impl.OpenApiService)2 OpenAPIBuildException (fish.payara.microprofile.openapi.api.OpenAPIBuildException)1 OpenAPIImpl (fish.payara.microprofile.openapi.impl.model.OpenAPIImpl)1 BaseProcessor (fish.payara.microprofile.openapi.impl.processor.BaseProcessor)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 OpenAPI (org.eclipse.microprofile.openapi.models.OpenAPI)1