Search in sources :

Example 1 with ServerImpl

use of io.smallrye.openapi.api.models.servers.ServerImpl in project smallrye-open-api by smallrye.

the class ServerReader method readServer.

/**
 * Reads a single Server annotation.
 *
 * @param annotationInstance the {@literal @}Server annotations instance
 * @return Server model
 */
public static Server readServer(final AnnotationInstance annotationInstance) {
    if (annotationInstance != null) {
        IoLogging.logger.singleAnnotation("@Server");
        Server server = new ServerImpl();
        server.setUrl(JandexUtil.stringValue(annotationInstance, ServerConstant.PROP_URL));
        server.setDescription(JandexUtil.stringValue(annotationInstance, ServerConstant.PROP_DESCRIPTION));
        server.setVariables(ServerVariableReader.readServerVariables(annotationInstance.value(ServerConstant.PROP_VARIABLES)));
        return server;
    }
    return null;
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) ServerImpl(io.smallrye.openapi.api.models.servers.ServerImpl)

Example 2 with ServerImpl

use of io.smallrye.openapi.api.models.servers.ServerImpl in project smallrye-open-api by smallrye.

the class ServerReader method readServer.

/**
 * Reads a list of {@link Server} OpenAPI nodes.
 *
 * @param node the json array
 * @return a List of Server models
 */
public static Server readServer(final JsonNode node) {
    if (node != null && node.isObject()) {
        IoLogging.logger.singleJsonNode("Server");
        Server server = new ServerImpl();
        server.setUrl(JsonUtil.stringProperty(node, ServerConstant.PROP_URL));
        server.setDescription(JsonUtil.stringProperty(node, ServerConstant.PROP_DESCRIPTION));
        server.setVariables(ServerVariableReader.readServerVariables(node.get(ServerConstant.PROP_VARIABLES)));
        ExtensionReader.readExtensions(node, server);
        return server;
    }
    return null;
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) ServerImpl(io.smallrye.openapi.api.models.servers.ServerImpl)

Example 3 with ServerImpl

use of io.smallrye.openapi.api.models.servers.ServerImpl in project smallrye-open-api by smallrye.

the class ConfigUtil method configureServers.

/**
 * Configures the servers for a PathItem.
 *
 * @param config OpenApiConfig
 * @param pathName String representing the pathName
 * @param pathItem String representing the pathItem
 */
protected static void configureServers(OpenApiConfig config, String pathName, PathItem pathItem) {
    if (pathItem == null) {
        return;
    }
    Set<String> pathServers = config.pathServers(pathName);
    if (pathServers != null && !pathServers.isEmpty()) {
        pathItem.servers(new ArrayList<>());
        for (String pathServer : pathServers) {
            Server server = new ServerImpl();
            server.setUrl(pathServer);
            pathItem.addServer(server);
        }
    }
    configureServers(config, pathItem.getGET());
    configureServers(config, pathItem.getPUT());
    configureServers(config, pathItem.getPOST());
    configureServers(config, pathItem.getDELETE());
    configureServers(config, pathItem.getHEAD());
    configureServers(config, pathItem.getOPTIONS());
    configureServers(config, pathItem.getPATCH());
    configureServers(config, pathItem.getTRACE());
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) ServerImpl(io.smallrye.openapi.api.models.servers.ServerImpl)

Example 4 with ServerImpl

use of io.smallrye.openapi.api.models.servers.ServerImpl in project org.openntf.xsp.jakartaee by OpenNTF.

the class AbstractOpenAPIResource method buildOpenAPI.

protected OpenAPI buildOpenAPI() throws IOException, NotesException {
    Set<Class<?>> classes = new HashSet<>();
    classes.addAll(application.getClasses());
    classes.add(application.getClass());
    Index index = Index.of(classes);
    Config mpConfig = CDI.current().select(Config.class).get();
    OpenApiConfig config = OpenApiConfigImpl.fromConfig(mpConfig);
    ClassLoader cl = new DelegatingClassLoader(OpenApiProcessor.class.getClassLoader(), Thread.currentThread().getContextClassLoader());
    OpenAPI openapi;
    synchronized (OpenApiProcessor.class) {
        // OpenApiProcessor appears to be not thread-safe
        openapi = OpenApiProcessor.bootstrap(config, index, cl);
    }
    NotesContext notesContext = NotesContext.getCurrent();
    Database database = notesContext.getCurrentDatabase();
    Info info = openapi.getInfo();
    String existingTitle = config.getInfoTitle();
    if (existingTitle == null || existingTitle.isEmpty()) {
        info.setTitle(database.getTitle());
    } else {
        info.setTitle(existingTitle);
    }
    String existingVersion = config.getInfoVersion();
    if (existingVersion == null || existingVersion.isEmpty()) {
        String templateBuild = getVersionNumber(database);
        if (templateBuild != null && !templateBuild.isEmpty()) {
            info.setVersion(templateBuild);
        } else {
            info.setVersion(existingVersion);
        }
    } else {
        info.setVersion(existingVersion);
    }
    // Build a URI to the base of JAX-RS
    Set<String> servers = config.servers();
    if (servers == null || servers.isEmpty()) {
        Server server = new ServerImpl();
        URI uri = URI.create(req.getRequestURL().toString());
        String jaxrsRoot = JAXRSServletFactory.getServletPath(notesContext.getModule());
        uri = uri.resolve(PathUtil.concat(req.getContextPath(), jaxrsRoot, '/'));
        String uriString = uri.toString();
        if (uriString.endsWith("/")) {
            // $NON-NLS-1$
            uriString = uriString.substring(0, uriString.length() - 1);
        }
        server.setUrl(uriString);
        openapi.addServer(server);
    }
    return openapi;
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) Config(org.eclipse.microprofile.config.Config) OpenApiConfig(io.smallrye.openapi.api.OpenApiConfig) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) Index(org.jboss.jandex.Index) OpenApiProcessor(io.smallrye.openapi.runtime.OpenApiProcessor) Info(org.eclipse.microprofile.openapi.models.info.Info) DelegatingClassLoader(org.openntf.xsp.jakartaee.DelegatingClassLoader) URI(java.net.URI) ServerImpl(io.smallrye.openapi.api.models.servers.ServerImpl) OpenApiConfig(io.smallrye.openapi.api.OpenApiConfig) Database(lotus.domino.Database) DelegatingClassLoader(org.openntf.xsp.jakartaee.DelegatingClassLoader) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) HashSet(java.util.HashSet)

Example 5 with ServerImpl

use of io.smallrye.openapi.api.models.servers.ServerImpl in project smallrye-open-api by smallrye.

the class ConfigUtil method configureServers.

protected static final void configureServers(OpenApiConfig config, OpenAPI oai) {
    // Start with the global servers.
    Set<String> servers = config.servers();
    if (servers != null && !servers.isEmpty()) {
        oai.servers(new ArrayList<>());
        for (String server : servers) {
            Server s = new ServerImpl();
            s.setUrl(server);
            oai.addServer(s);
        }
    }
    // Now the PathItem and Operation servers
    Map<String, PathItem> pathItems = oai.getPaths().getPathItems();
    if (pathItems != null) {
        pathItems.entrySet().forEach(entry -> configureServers(config, entry.getKey(), entry.getValue()));
    }
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) Server(org.eclipse.microprofile.openapi.models.servers.Server) ServerImpl(io.smallrye.openapi.api.models.servers.ServerImpl)

Aggregations

ServerImpl (io.smallrye.openapi.api.models.servers.ServerImpl)6 Server (org.eclipse.microprofile.openapi.models.servers.Server)6 NotesContext (com.ibm.domino.xsp.module.nsf.NotesContext)1 OpenApiConfig (io.smallrye.openapi.api.OpenApiConfig)1 OpenApiProcessor (io.smallrye.openapi.runtime.OpenApiProcessor)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 Database (lotus.domino.Database)1 Config (org.eclipse.microprofile.config.Config)1 OpenAPI (org.eclipse.microprofile.openapi.models.OpenAPI)1 PathItem (org.eclipse.microprofile.openapi.models.PathItem)1 Info (org.eclipse.microprofile.openapi.models.info.Info)1 Index (org.jboss.jandex.Index)1 DelegatingClassLoader (org.openntf.xsp.jakartaee.DelegatingClassLoader)1