Search in sources :

Example 6 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 7 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 8 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 9 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)

Example 10 with Server

use of org.eclipse.microprofile.openapi.models.servers.Server in project empoa by OpenAPITools.

the class AbstractElementSerializerTest method testEmptyServerToJson.

@Test
public void testEmptyServerToJson() throws Exception {
    Server server = OASFactory.createServer();
    String json = convertToJson(server);
    assertThatJson(json).isEqualTo("{}");
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) Test(org.junit.jupiter.api.Test)

Aggregations

Server (org.eclipse.microprofile.openapi.models.servers.Server)47 SecurityRequirement (org.eclipse.microprofile.openapi.models.security.SecurityRequirement)11 Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)10 OpenAPI (org.eclipse.microprofile.openapi.models.OpenAPI)8 PathItem (org.eclipse.microprofile.openapi.models.PathItem)8 Tag (org.eclipse.microprofile.openapi.models.tags.Tag)8 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)7 ServerImpl (io.smallrye.openapi.api.models.servers.ServerImpl)6 List (java.util.List)6 Operation (org.eclipse.microprofile.openapi.models.Operation)6 Info (org.eclipse.microprofile.openapi.models.info.Info)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ArrayList (java.util.ArrayList)5 Components (org.eclipse.microprofile.openapi.models.Components)5 SecurityScheme (org.eclipse.microprofile.openapi.models.security.SecurityScheme)5 ServerVariable (org.eclipse.microprofile.openapi.models.servers.ServerVariable)5 Test (org.junit.jupiter.api.Test)5 ServerImpl (fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)4 Map (java.util.Map)4 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)4