Search in sources :

Example 6 with ServerImpl

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

the class ApplicationProcessor method visitServer.

@Override
public void visitServer(AnnotationModel server, AnnotatedElement element, ApiContext context) {
    if (element instanceof MethodModel) {
        Server newServer = new ServerImpl();
        context.getWorkingOperation().addServer(newServer);
        ServerImpl.merge(ServerImpl.createInstance(server, context), newServer, true);
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) Server(org.eclipse.microprofile.openapi.models.servers.Server) ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)

Example 7 with ServerImpl

use of fish.payara.microprofile.openapi.impl.model.servers.ServerImpl 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)

Example 8 with ServerImpl

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

the class OpenAPIImpl method merge.

public static void merge(OpenAPI from, OpenAPI to, boolean override, ApiContext context) {
    if (from == null) {
        return;
    }
    to.setOpenapi(mergeProperty(to.getOpenapi(), from.getOpenapi(), override));
    // Handle @Info
    if (from.getInfo() != null) {
        if (to.getInfo() == null) {
            to.setInfo(new InfoImpl());
        }
        InfoImpl.merge(from.getInfo(), to.getInfo(), override);
    }
    // Handle @Servers
    if (from.getServers() != null) {
        for (Server server : from.getServers()) {
            if (server != null) {
                Server newServer = new ServerImpl();
                ServerImpl.merge(server, newServer, true);
                if (!to.getServers().contains(newServer)) {
                    to.addServer(newServer);
                }
            }
        }
    }
    // Handle @ExternalDocumentation
    if (from.getExternalDocs() != null) {
        if (to.getExternalDocs() == null) {
            to.setExternalDocs(new ExternalDocumentationImpl());
        }
        ExternalDocumentationImpl.merge(from.getExternalDocs(), to.getExternalDocs(), override);
    }
    // Handle @SecurityRequirement
    if (from.getSecurity() != null) {
        for (SecurityRequirement requirement : from.getSecurity()) {
            if (requirement != null) {
                SecurityRequirement newRequirement = new SecurityRequirementImpl();
                SecurityRequirementImpl.merge(requirement, newRequirement);
                if (!to.getSecurity().contains(newRequirement)) {
                    to.addSecurityRequirement(newRequirement);
                }
            }
        }
    }
    // Handle @Tags
    if (from.getTags() != null) {
        for (Tag tag : from.getTags()) {
            if (tag != null) {
                if (to.getTags() == null) {
                    to.setTags(createList());
                }
                Tag newTag = new TagImpl();
                TagImpl.merge(tag, newTag, override);
                to.addTag(newTag);
            }
        }
    }
    // Handle @Components
    ComponentsImpl.merge(from.getComponents(), to.getComponents(), override, context);
    PathsImpl.merge(from.getPaths(), to.getPaths(), override);
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl) TagImpl(fish.payara.microprofile.openapi.impl.model.tags.TagImpl) SecurityRequirementImpl(fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) InfoImpl(fish.payara.microprofile.openapi.impl.model.info.InfoImpl) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement)

Aggregations

ServerImpl (fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)8 SecurityRequirementImpl (fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl)4 Server (org.eclipse.microprofile.openapi.models.servers.Server)4 InfoImpl (fish.payara.microprofile.openapi.impl.model.info.InfoImpl)3 TagImpl (fish.payara.microprofile.openapi.impl.model.tags.TagImpl)3 PathItem (org.eclipse.microprofile.openapi.models.PathItem)3 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)2 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)2 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)2 Operation (org.eclipse.microprofile.openapi.models.Operation)2 SecurityRequirement (org.eclipse.microprofile.openapi.models.security.SecurityRequirement)2 Tag (org.eclipse.microprofile.openapi.models.tags.Tag)2 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)2 PathItemImpl (fish.payara.microprofile.openapi.impl.model.PathItemImpl)1 ExampleImpl (fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)1 HeaderImpl (fish.payara.microprofile.openapi.impl.model.headers.HeaderImpl)1 ContactImpl (fish.payara.microprofile.openapi.impl.model.info.ContactImpl)1 LicenseImpl (fish.payara.microprofile.openapi.impl.model.info.LicenseImpl)1 LinkImpl (fish.payara.microprofile.openapi.impl.model.links.LinkImpl)1 ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)1