use of io.smallrye.openapi.runtime.OpenApiProcessor 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;
}
Aggregations