use of org.eclipse.microprofile.openapi.models.info.Info in project wildfly by wildfly.
the class OpenAPIModelServiceConfigurator method get.
@Override
public OpenAPI get() {
OpenApiConfig config = new OpenApiConfigImpl(this.config);
IndexView indexView = new FilteredIndexView(this.index, config);
OpenAPIDocumentBuilder builder = new OpenAPIDocumentBuilder();
builder.config(config);
Map.Entry<VirtualFile, Format> entry = findStaticFile(this.root);
if (entry != null) {
VirtualFile file = entry.getKey();
Format format = entry.getValue();
try (OpenApiStaticFile staticFile = new OpenApiStaticFile(file.openStream(), format)) {
builder.staticFileModel(OpenApiProcessor.modelFromStaticFile(staticFile));
} catch (IOException e) {
throw MicroProfileOpenAPILogger.LOGGER.failedToLoadStaticFile(e, file.getPathNameRelativeTo(this.root), this.deploymentName);
}
}
builder.annotationsModel(OpenApiProcessor.modelFromAnnotations(config, AnnotationScanner.class.getClassLoader(), indexView));
builder.readerModel(OpenApiProcessor.modelFromReader(config, this.module.getClassLoader()));
builder.filter(OpenApiProcessor.getFilter(config, this.module.getClassLoader()));
OpenAPI model = builder.build();
// Generate default title and description based on web metadata
DescriptionGroupMetaData descriptionMetaData = this.metaData.getDescriptionGroup();
String displayName = (descriptionMetaData != null) ? descriptionMetaData.getDisplayName() : null;
String title = (displayName != null) ? displayName : this.deploymentName;
String description = (descriptionMetaData != null) ? descriptionMetaData.getDescription() : null;
Info info = model.getInfo();
// Override SmallRye's default title
if (info.getTitle().equals(DEFAULT_TITLE)) {
info.setTitle(title);
}
if (info.getDescription() == null) {
info.setDescription(description);
}
Host host = this.host.get();
List<UndertowListener> listeners = host.getServer().getListeners();
if (model.getServers() == null) {
// Generate Server entries if none exist
String contextPath = this.info.get().getContextPath();
if (this.config.getOptionalValue(RELATIVE_SERVER_URLS, Boolean.class).orElse(Boolean.TRUE).booleanValue()) {
model.setServers(Collections.singletonList(OASFactory.createServer().url(contextPath)));
} else {
int aliases = host.getAllAliases().size();
int size = 0;
for (UndertowListener listener : listeners) {
size += aliases + listener.getSocketBinding().getClientMappings().size();
}
List<Server> servers = new ArrayList<>(size);
for (UndertowListener listener : listeners) {
SocketBinding binding = listener.getSocketBinding();
Set<String> virtualHosts = new TreeSet<>(host.getAllAliases());
// The name of the host is not a real virtual host (e.g. default-host)
virtualHosts.remove(host.getName());
InetAddress address = binding.getAddress();
// Omit wildcard addresses
if (!address.isAnyLocalAddress()) {
virtualHosts.add(address.getCanonicalHostName());
}
for (String virtualHost : virtualHosts) {
Server server = createServer(listener.getProtocol(), virtualHost, binding.getPort(), contextPath);
if (server != null) {
servers.add(server);
}
}
for (ClientMapping mapping : binding.getClientMappings()) {
Server server = createServer(listener.getProtocol(), mapping.getDestinationAddress(), mapping.getDestinationPort(), contextPath);
if (server != null) {
servers.add(server);
}
}
}
model.setServers(servers);
}
}
if (listeners.stream().map(UndertowListener::getProtocol).noneMatch(REQUISITE_LISTENERS::contains)) {
LOGGER.requiredListenersNotFound(host.getServer().getName(), REQUISITE_LISTENERS);
}
return model;
}
use of org.eclipse.microprofile.openapi.models.info.Info in project Payara by payara.
the class InfoImpl method createInstance.
public static Info createInstance(AnnotationModel annotation) {
Info from = new InfoImpl();
from.setTitle(annotation.getValue("title", String.class));
from.setDescription(annotation.getValue("description", String.class));
from.setTermsOfService(annotation.getValue("termsOfService", String.class));
AnnotationModel contact = annotation.getValue("contact", AnnotationModel.class);
if (contact != null) {
from.setContact(ContactImpl.createInstance(contact));
}
AnnotationModel license = annotation.getValue("license", AnnotationModel.class);
if (license != null) {
from.setLicense(LicenseImpl.createInstance(license));
}
from.setVersion(annotation.getValue("version", String.class));
return from;
}
use of org.eclipse.microprofile.openapi.models.info.Info in project Payara by payara.
the class ModelInvariantsTest method addKeyValueIgnoresNull.
@Test
public void addKeyValueIgnoresNull() {
BiPredicate<Extensible<?>, String> hasExtension = (obj, key) -> obj.getExtensions().containsKey(key);
assertAddIgnoresNull(new CallbackImpl(), Callback::addPathItem, Callback::hasPathItem);
assertAddIgnoresNull(new CallbackImpl(), Callback::addExtension, hasExtension);
assertAddIgnoresNull(new ExampleImpl(), Example::addExtension, hasExtension);
assertAddIgnoresNull(new HeaderImpl(), Header::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new HeaderImpl(), Header::addExtension, hasExtension);
assertAddIgnoresNull(new ContactImpl(), Contact::addExtension, hasExtension);
assertAddIgnoresNull(new InfoImpl(), Info::addExtension, hasExtension);
assertAddIgnoresNull(new LicenseImpl(), License::addExtension, hasExtension);
assertAddIgnoresNull(new LinkImpl(), Link::addParameter, (obj, key) -> obj.getParameters().containsKey(key));
assertAddIgnoresNull(new LinkImpl(), Link::addExtension, hasExtension);
assertAddIgnoresNull(new ContentImpl(), Content::addMediaType, Content::hasMediaType);
assertAddIgnoresNull(new DiscriminatorImpl(), Discriminator::addMapping, (obj, key) -> obj.getMapping().containsKey(key));
assertAddIgnoresNull(new EncodingImpl(), Encoding::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
assertAddIgnoresNull(new EncodingImpl(), Encoding::addExtension, hasExtension);
assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addEncoding, (obj, key) -> obj.getEncoding().containsKey(key));
assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addExtension, hasExtension);
assertAddIgnoresNull(new SchemaImpl(), Schema::addProperty, (obj, key) -> obj.getProperties().containsKey(key));
assertAddIgnoresNull(new SchemaImpl(), Schema::addExtension, hasExtension);
assertAddIgnoresNull(new XMLImpl(), XML::addExtension, hasExtension);
assertAddIgnoresNull(new ParameterImpl(), Parameter::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new ParameterImpl(), Parameter::addExtension, hasExtension);
assertAddIgnoresNull(new RequestBodyImpl(), RequestBody::addExtension, hasExtension);
assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addLink, (obj, key) -> obj.getLinks().containsKey(key));
assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addExtension, hasExtension);
assertAddIgnoresNull(new APIResponsesImpl(), APIResponses::addAPIResponse, APIResponses::hasAPIResponse);
assertAddIgnoresNull(new APIResponsesImpl(), APIResponses::addExtension, hasExtension);
assertAddIgnoresNull(new OAuthFlowImpl(), OAuthFlow::addExtension, hasExtension);
assertAddIgnoresNull(new OAuthFlowsImpl(), OAuthFlows::addExtension, hasExtension);
assertAddIgnoresNull(new SecuritySchemeImpl(), SecurityScheme::addExtension, hasExtension);
assertAddIgnoresNull(new ServerImpl(), Server::addExtension, hasExtension);
assertAddIgnoresNull(new ServerVariableImpl(), ServerVariable::addExtension, hasExtension);
assertAddIgnoresNull(new TagImpl(), Tag::addExtension, hasExtension);
assertAddIgnoresNull(new ComponentsImpl(), Components::addCallback, (obj, key) -> obj.getCallbacks().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addLink, (obj, key) -> obj.getLinks().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addParameter, (obj, key) -> obj.getParameters().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addRequestBody, (obj, key) -> obj.getRequestBodies().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addResponse, (obj, key) -> obj.getResponses().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addSchema, (obj, key) -> obj.getSchemas().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addSecurityScheme, (obj, key) -> obj.getSecuritySchemes().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addExtension, hasExtension);
assertAddIgnoresNull(new ExternalDocumentationImpl(), ExternalDocumentation::addExtension, hasExtension);
assertAddIgnoresNull(new OpenAPIImpl(), OpenAPI::addExtension, hasExtension);
assertAddIgnoresNull(new OperationImpl(), Operation::addCallback, (obj, key) -> obj.getCallbacks().containsKey(key));
assertAddIgnoresNull(new OperationImpl(), Operation::addExtension, hasExtension);
assertAddIgnoresNull(new PathItemImpl(), PathItem::addExtension, hasExtension);
assertAddIgnoresNull(new PathsImpl(), Paths::addPathItem, Paths::hasPathItem);
assertAddIgnoresNull(new PathsImpl(), Paths::addExtension, hasExtension);
}
use of org.eclipse.microprofile.openapi.models.info.Info in project Payara by payara.
the class OpenApiBuilderTest method setupDocument.
@Before
public void setupDocument() {
document = createObject(OpenAPI.class);
Info info = createObject(Info.class);
info.setTitle("title");
info.setVersion("version");
document.setInfo(info);
document.setOpenapi("3.0.0");
setupBaseDocument(document);
}
Aggregations