Search in sources :

Example 6 with PathItemImpl

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

the class ApplicationProcessor method visitGET.

// JAX-RS method handlers
@Override
public void visitGET(AnnotationModel get, MethodModel element, ApiContext context) {
    if (context.getPath() == null) {
        return;
    }
    // Get or create the path item
    PathItem pathItem = context.getApi().getPaths().getPathItems().getOrDefault(context.getPath(), new PathItemImpl());
    context.getApi().getPaths().addPathItem(context.getPath(), pathItem);
    OperationImpl operation = new OperationImpl();
    pathItem.setGET(operation);
    operation.setOperationId(element.getName());
    operation.setMethod(HttpMethod.GET);
    // Add the default request
    insertDefaultRequestBody(context, operation, element);
    // Add the default response
    insertDefaultResponse(context, operation, element);
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl)

Example 7 with PathItemImpl

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

the class ApplicationProcessor method visitPATCH.

@Override
public void visitPATCH(AnnotationModel patch, MethodModel element, ApiContext context) {
    if (context.getPath() == null) {
        return;
    }
    // Get or create the path item
    PathItem pathItem = context.getApi().getPaths().getPathItems().getOrDefault(context.getPath(), new PathItemImpl());
    context.getApi().getPaths().addPathItem(context.getPath(), pathItem);
    OperationImpl operation = new OperationImpl();
    pathItem.setPATCH(operation);
    operation.setOperationId(element.getName());
    operation.setMethod(HttpMethod.PATCH);
    // Add the default request
    insertDefaultRequestBody(context, operation, element);
    // Add the default response
    insertDefaultResponse(context, operation, element);
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl)

Example 8 with PathItemImpl

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

the class ApplicationProcessor method visitHEAD.

@Override
public void visitHEAD(AnnotationModel head, MethodModel element, ApiContext context) {
    if (context.getPath() == null) {
        return;
    }
    // Get or create the path item
    PathItem pathItem = context.getApi().getPaths().getPathItems().getOrDefault(context.getPath(), new PathItemImpl());
    context.getApi().getPaths().addPathItem(context.getPath(), pathItem);
    OperationImpl operation = new OperationImpl();
    pathItem.setHEAD(operation);
    operation.setOperationId(element.getName());
    operation.setMethod(HttpMethod.HEAD);
    // Add the default request
    insertDefaultRequestBody(context, operation, element);
    // Add the default response
    insertDefaultResponse(context, operation, element);
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl)

Example 9 with PathItemImpl

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

the class ApplicationProcessor method visitPOST.

@Override
public void visitPOST(AnnotationModel post, MethodModel element, ApiContext context) {
    if (context.getPath() == null) {
        return;
    }
    // Get or create the path item
    PathItem pathItem = context.getApi().getPaths().getPathItems().getOrDefault(context.getPath(), new PathItemImpl());
    context.getApi().getPaths().addPathItem(context.getPath(), pathItem);
    OperationImpl operation = new OperationImpl();
    pathItem.setPOST(operation);
    operation.setOperationId(element.getName());
    operation.setMethod(HttpMethod.POST);
    // Add the default request
    insertDefaultRequestBody(context, operation, element);
    // Add the default response
    insertDefaultResponse(context, operation, element);
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl)

Example 10 with PathItemImpl

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

the class BaseProcessor method process.

@Override
public OpenAPI process(OpenAPI api, OpenApiConfiguration config) {
    // Set the OpenAPI version if it hasn't been set
    if (api.getOpenapi() == null) {
        api.setOpenapi("3.0.0");
    }
    // Set the info if it hasn't been set
    if (api.getInfo() == null) {
        api.setInfo(new InfoImpl().title("Deployed Resources").version("1.0.0"));
    }
    if (config != null) {
        // Add the config specified servers
        if (!config.getServers().isEmpty()) {
            // Clear all the other servers
            api.setServers(new ArrayList<>());
            // Add all the specified ones
            config.getServers().forEach(serverUrl -> api.addServer(new ServerImpl().url(serverUrl)));
        }
        // Add the default server if there are none
        if (api.getServers().isEmpty()) {
            for (URL baseURL : baseURLs) {
                api.addServer(new ServerImpl().url(baseURL.toString()).description("Default Server."));
            }
        }
        // Add the path servers
        for (Entry<String, Set<String>> entry : config.getPathServerMap().entrySet()) {
            // Get the normalised path
            String path = normaliseUrl(entry.getKey());
            // If the path doesn't exist, create it
            if (!api.getPaths().hasPathItem(path)) {
                api.getPaths().addPathItem(path, new PathItemImpl());
            }
            // Clear the current list of servers
            api.getPaths().getPathItem(path).setServers(new ArrayList<>());
            // Add each url
            for (String serverUrl : entry.getValue()) {
                api.getPaths().getPathItem(path).addServer(new ServerImpl().url(serverUrl));
            }
        }
        // Add the operation servers
        for (Entry<String, Set<String>> entry : config.getOperationServerMap().entrySet()) {
            // Find the matching operation
            for (PathItem pathItem : api.getPaths().getPathItems().values()) {
                for (Operation operation : pathItem.getOperations().values()) {
                    if (operation.getOperationId().equals(entry.getKey())) {
                        // Clear the current list of servers
                        operation.setServers(new ArrayList<>());
                        // Add each server url to the operation
                        for (String serverUrl : entry.getValue()) {
                            operation.addServer(new ServerImpl().url(serverUrl));
                        }
                    }
                }
            }
        }
    }
    removeEmptyPaths(api.getPaths());
    return api;
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) Set(java.util.Set) HashSet(java.util.HashSet) ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl) Operation(org.eclipse.microprofile.openapi.models.Operation) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl) InfoImpl(fish.payara.microprofile.openapi.impl.model.info.InfoImpl) URL(java.net.URL)

Aggregations

PathItemImpl (fish.payara.microprofile.openapi.impl.model.PathItemImpl)10 PathItem (org.eclipse.microprofile.openapi.models.PathItem)10 OperationImpl (fish.payara.microprofile.openapi.impl.model.OperationImpl)7 HashSet (java.util.HashSet)2 Operation (org.eclipse.microprofile.openapi.models.Operation)2 InfoImpl (fish.payara.microprofile.openapi.impl.model.info.InfoImpl)1 ServerImpl (fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)1 ModelUtils.getOrCreateOperation (fish.payara.microprofile.openapi.impl.model.util.ModelUtils.getOrCreateOperation)1 URL (java.net.URL)1 Set (java.util.Set)1