Search in sources :

Example 1 with BaseProcessor

use of fish.payara.microprofile.openapi.impl.processor.BaseProcessor 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 BaseProcessor

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

the class OpenAPISupplier method get.

@Override
public synchronized OpenAPI get() {
    if (this.document != null) {
        return this.document;
    }
    if (!enabled) {
        return null;
    }
    try {
        final Parser parser = Globals.get(ApplicationLifecycle.class).getDeployableParser(archive, true, true, StructuredDeploymentTracing.create(applicationId), Logger.getLogger(OpenApiService.class.getName()));
        final Types types = parser.getContext().getTypes();
        OpenAPI doc = new OpenAPIImpl();
        try {
            final List<URL> baseURLs = getServerURL(contextRoot);
            doc = new ConfigPropertyProcessor().process(doc, config);
            doc = new ModelReaderProcessor().process(doc, config);
            doc = new FileProcessor(classLoader).process(doc, config);
            doc = new ApplicationProcessor(types, filterTypes(archive, config, types), classLoader).process(doc, config);
            doc = new BaseProcessor(baseURLs).process(doc, config);
            doc = new FilterProcessor().process(doc, config);
        } finally {
            this.document = doc;
        }
        return this.document;
    } catch (Exception ex) {
        throw new RuntimeException("An error occurred while creating the OpenAPI document.", ex);
    }
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) FileProcessor(fish.payara.microprofile.openapi.impl.processor.FileProcessor) OpenAPIImpl(fish.payara.microprofile.openapi.impl.model.OpenAPIImpl) FilterProcessor(fish.payara.microprofile.openapi.impl.processor.FilterProcessor) ApplicationLifecycle(com.sun.enterprise.v3.server.ApplicationLifecycle) ModelReaderProcessor(fish.payara.microprofile.openapi.impl.processor.ModelReaderProcessor) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) MultiException(org.glassfish.hk2.api.MultiException) Parser(org.glassfish.hk2.classmodel.reflect.Parser) ConfigPropertyProcessor(fish.payara.microprofile.openapi.impl.processor.ConfigPropertyProcessor) ApplicationProcessor(fish.payara.microprofile.openapi.impl.processor.ApplicationProcessor) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) BaseProcessor(fish.payara.microprofile.openapi.impl.processor.BaseProcessor)

Example 3 with BaseProcessor

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

the class ApplicationProcessedDocument method createDocument.

public static OpenAPI createDocument(Class<? extends OASFilter> filter, Class<?>... extraClasses) {
    try {
        ApplicationClassLoader appClassLoader = new ApplicationClassLoader(new HashSet<>(asList(extraClasses)));
        OpenAPIImpl document = new OpenAPIImpl();
        // Apply base processor
        new BaseProcessor(asList(new URL("http://localhost:8080/testlocation_123"))).process(document, null);
        // Apply application processor
        new ApplicationProcessor(getTypes(), getApplicationTypes(extraClasses), appClassLoader).process(document, null);
        if (filter != null) {
            new FilterProcessor(filter.newInstance()).process(document, null);
        }
        return document;
    } catch (IOException | IllegalAccessException | InstantiationException | InterruptedException ex) {
        throw new AssertionError("Failed to build document.", ex);
    }
}
Also used : OpenAPIImpl(fish.payara.microprofile.openapi.impl.model.OpenAPIImpl) FilterProcessor(fish.payara.microprofile.openapi.impl.processor.FilterProcessor) IOException(java.io.IOException) ApplicationClassLoader(fish.payara.microprofile.openapi.resource.classloader.ApplicationClassLoader) URL(java.net.URL) ApplicationProcessor(fish.payara.microprofile.openapi.impl.processor.ApplicationProcessor) BaseProcessor(fish.payara.microprofile.openapi.impl.processor.BaseProcessor)

Aggregations

OpenAPIImpl (fish.payara.microprofile.openapi.impl.model.OpenAPIImpl)3 BaseProcessor (fish.payara.microprofile.openapi.impl.processor.BaseProcessor)3 IOException (java.io.IOException)3 ApplicationProcessor (fish.payara.microprofile.openapi.impl.processor.ApplicationProcessor)2 FilterProcessor (fish.payara.microprofile.openapi.impl.processor.FilterProcessor)2 URL (java.net.URL)2 OpenAPI (org.eclipse.microprofile.openapi.models.OpenAPI)2 ApplicationLifecycle (com.sun.enterprise.v3.server.ApplicationLifecycle)1 OpenAPIBuildException (fish.payara.microprofile.openapi.api.OpenAPIBuildException)1 OpenApiService (fish.payara.microprofile.openapi.impl.OpenApiService)1 ConfigPropertyProcessor (fish.payara.microprofile.openapi.impl.processor.ConfigPropertyProcessor)1 FileProcessor (fish.payara.microprofile.openapi.impl.processor.FileProcessor)1 ModelReaderProcessor (fish.payara.microprofile.openapi.impl.processor.ModelReaderProcessor)1 ApplicationClassLoader (fish.payara.microprofile.openapi.resource.classloader.ApplicationClassLoader)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 MultiException (org.glassfish.hk2.api.MultiException)1