Search in sources :

Example 1 with Server

use of org.eclipse.microprofile.openapi.models.servers.Server in project wildfly-swarm by wildfly-swarm.

the class OpenApiParser method readServers.

/**
 * Reads a list of {@link Server} OpenAPI nodes.
 * @param node
 */
private List<Server> readServers(JsonNode node) {
    if (node == null || !node.isArray()) {
        return null;
    }
    ArrayNode nodes = (ArrayNode) node;
    List<Server> rval = new ArrayList<>(nodes.size());
    for (JsonNode serverNode : nodes) {
        ServerImpl model = new ServerImpl();
        model.setUrl(JsonUtil.stringProperty(serverNode, OpenApiConstants.PROP_URL));
        model.setDescription(JsonUtil.stringProperty(serverNode, OpenApiConstants.PROP_DESCRIPTION));
        model.setVariables(readServerVariables(serverNode.get(OpenApiConstants.PROP_VARIABLES)));
        readExtensions(serverNode, model);
        rval.add(model);
    }
    return rval;
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) ServerImpl(org.wildfly.swarm.microprofile.openapi.api.models.servers.ServerImpl) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with Server

use of org.eclipse.microprofile.openapi.models.servers.Server in project wildfly-swarm by wildfly-swarm.

the class OpenApiAnnotationScanner method readServers.

/**
 * Reads any Server annotations.  The annotation value is an array of Server annotations.
 * @param serverAnnos
 */
private List<Server> readServers(AnnotationValue serverAnnos) {
    if (serverAnnos == null) {
        return null;
    }
    LOG.debug("Processing an array of @Server annotations.");
    AnnotationInstance[] nestedArray = serverAnnos.asNestedArray();
    List<Server> servers = new ArrayList<>();
    for (AnnotationInstance serverAnno : nestedArray) {
        servers.add(readServer(serverAnno));
    }
    return servers;
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) ArrayList(java.util.ArrayList) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Example 3 with Server

use of org.eclipse.microprofile.openapi.models.servers.Server in project wildfly-swarm by wildfly-swarm.

the class OpenApiAnnotationScanner method jaxRsApplicationToOpenApi.

/**
 * Processes a JAX-RS {@link Application} and creates an {@link OpenAPI} model.  Performs
 * annotation scanning and other processing.  Returns a model unique to that single JAX-RS
 * app.
 * @param applicationClass
 */
private OpenAPIImpl jaxRsApplicationToOpenApi(ClassInfo applicationClass) {
    OpenAPIImpl oai = new OpenAPIImpl();
    oai.setOpenapi(OpenApiConstants.OPEN_API_VERSION);
    // Get the @ApplicationPath info and save it for later (also support @Path which seems nonstandard but common).
    // //////////////////////////////////////
    AnnotationInstance appPathAnno = JandexUtil.getClassAnnotation(applicationClass, OpenApiConstants.DOTNAME_APPLICATION_PATH);
    if (appPathAnno == null) {
        appPathAnno = JandexUtil.getClassAnnotation(applicationClass, OpenApiConstants.DOTNAME_PATH);
    }
    if (appPathAnno != null) {
        this.currentAppPath = appPathAnno.value().asString();
    } else {
        this.currentAppPath = "/";
    }
    // Get the @OpenAPIDefinition annotation and process it.
    // //////////////////////////////////////
    AnnotationInstance openApiDefAnno = JandexUtil.getClassAnnotation(applicationClass, OpenApiConstants.DOTNAME_OPEN_API_DEFINITION);
    if (openApiDefAnno != null) {
        processDefinition(oai, openApiDefAnno);
    }
    // Process @SecurityScheme annotations
    // //////////////////////////////////////
    List<AnnotationInstance> securitySchemeAnnotations = JandexUtil.getRepeatableAnnotation(applicationClass, OpenApiConstants.DOTNAME_SECURITY_SCHEME, OpenApiConstants.DOTNAME_SECURITY_SCHEMES);
    for (AnnotationInstance annotation : securitySchemeAnnotations) {
        String name = JandexUtil.stringValue(annotation, OpenApiConstants.PROP_SECURITY_SCHEME_NAME);
        if (name == null && JandexUtil.isRef(annotation)) {
            name = JandexUtil.nameFromRef(annotation);
        }
        if (name != null) {
            SecurityScheme securityScheme = readSecurityScheme(annotation);
            Components components = ModelUtil.components(oai);
            components.addSecurityScheme(name, securityScheme);
        }
    }
    // Process @Server annotations
    // /////////////////////////////////
    List<AnnotationInstance> serverAnnotations = JandexUtil.getRepeatableAnnotation(applicationClass, OpenApiConstants.DOTNAME_SERVER, OpenApiConstants.DOTNAME_SERVERS);
    for (AnnotationInstance annotation : serverAnnotations) {
        Server server = readServer(annotation);
        oai.addServer(server);
    }
    return oai;
}
Also used : Components(org.eclipse.microprofile.openapi.models.Components) Server(org.eclipse.microprofile.openapi.models.servers.Server) OpenAPIImpl(org.wildfly.swarm.microprofile.openapi.api.models.OpenAPIImpl) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Example 4 with Server

use of org.eclipse.microprofile.openapi.models.servers.Server in project wildfly-swarm by wildfly-swarm.

the class FilterUtil method filterServers.

/**
 * Filters the given model.
 * @param filter
 * @param models
 */
private static void filterServers(OASFilter filter, List<Server> models) {
    if (models == null) {
        return;
    }
    ListIterator<Server> iterator = models.listIterator();
    while (iterator.hasNext()) {
        Server model = iterator.next();
        filterServer(filter, model);
        if (filter.filterServer(model) == null) {
            iterator.remove();
        }
    }
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server)

Example 5 with Server

use of org.eclipse.microprofile.openapi.models.servers.Server in project wildfly-swarm by wildfly-swarm.

the class ServersUtil method configureServers.

/**
 * Configures the servers for an Operation.
 * @param config
 * @param operation
 */
protected static void configureServers(OpenApiConfig config, Operation operation) {
    if (operation == null) {
        return;
    }
    if (operation.getOperationId() == null) {
        return;
    }
    Set<String> operationServers = config.operationServers(operation.getOperationId());
    if (operationServers != null && !operationServers.isEmpty()) {
        operation.servers(new ArrayList<>());
        for (String operationServer : operationServers) {
            Server server = new ServerImpl();
            server.setUrl(operationServer);
            operation.addServer(server);
        }
    }
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) ServerImpl(org.wildfly.swarm.microprofile.openapi.api.models.servers.ServerImpl)

Aggregations

Server (org.eclipse.microprofile.openapi.models.servers.Server)16 ServerImpl (fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)4 ServerImpl (org.wildfly.swarm.microprofile.openapi.api.models.servers.ServerImpl)4 ArrayList (java.util.ArrayList)3 PathItem (org.eclipse.microprofile.openapi.models.PathItem)3 SecurityRequirement (org.eclipse.microprofile.openapi.models.security.SecurityRequirement)3 Tag (org.eclipse.microprofile.openapi.models.tags.Tag)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 InfoImpl (fish.payara.microprofile.openapi.impl.model.info.InfoImpl)2 SecurityRequirementImpl (fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl)2 TagImpl (fish.payara.microprofile.openapi.impl.model.tags.TagImpl)2 Operation (org.eclipse.microprofile.openapi.models.Operation)2 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)2 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)2 Schema (org.eclipse.microprofile.openapi.models.media.Schema)2 Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)2 RequestBody (org.eclipse.microprofile.openapi.models.parameters.RequestBody)2 APIResponse (org.eclipse.microprofile.openapi.models.responses.APIResponse)2 APIResponses (org.eclipse.microprofile.openapi.models.responses.APIResponses)2 AnnotationInstance (org.jboss.jandex.AnnotationInstance)2