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();
}
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");
}
}
Aggregations