use of fish.payara.microprofile.openapi.impl.model.info.InfoImpl in project Payara by payara.
the class BaseProcessor method process.
@Override
public OpenAPI process(OpenAPI api, OpenApiConfiguration config) {
// Set the OpenAPI version if it hasn't been set
if (api.getOpenapi() == null) {
api.setOpenapi("3.0.0");
}
// Set the info if it hasn't been set
if (api.getInfo() == null) {
api.setInfo(new InfoImpl().title("Deployed Resources").version("1.0.0"));
}
if (config != null) {
// Add the config specified servers
if (!config.getServers().isEmpty()) {
// Clear all the other servers
api.setServers(new ArrayList<>());
// Add all the specified ones
config.getServers().forEach(serverUrl -> api.addServer(new ServerImpl().url(serverUrl)));
}
// Add the default server if there are none
if (api.getServers().isEmpty()) {
for (URL baseURL : baseURLs) {
api.addServer(new ServerImpl().url(baseURL.toString()).description("Default Server."));
}
}
// Add the path servers
for (Entry<String, Set<String>> entry : config.getPathServerMap().entrySet()) {
// Get the normalised path
String path = normaliseUrl(entry.getKey());
// If the path doesn't exist, create it
if (!api.getPaths().hasPathItem(path)) {
api.getPaths().addPathItem(path, new PathItemImpl());
}
// Clear the current list of servers
api.getPaths().getPathItem(path).setServers(new ArrayList<>());
// Add each url
for (String serverUrl : entry.getValue()) {
api.getPaths().getPathItem(path).addServer(new ServerImpl().url(serverUrl));
}
}
// Add the operation servers
for (Entry<String, Set<String>> entry : config.getOperationServerMap().entrySet()) {
// Find the matching operation
for (PathItem pathItem : api.getPaths().getPathItems().values()) {
for (Operation operation : pathItem.getOperations().values()) {
if (operation.getOperationId().equals(entry.getKey())) {
// Clear the current list of servers
operation.setServers(new ArrayList<>());
// Add each server url to the operation
for (String serverUrl : entry.getValue()) {
operation.addServer(new ServerImpl().url(serverUrl));
}
}
}
}
}
}
removeEmptyPaths(api.getPaths());
return api;
}
use of fish.payara.microprofile.openapi.impl.model.info.InfoImpl in project Payara by payara.
the class OpenAPIImpl method merge.
public static void merge(OpenAPI from, OpenAPI to, boolean override, ApiContext context) {
if (from == null) {
return;
}
to.setOpenapi(mergeProperty(to.getOpenapi(), from.getOpenapi(), override));
// Handle @Info
if (from.getInfo() != null) {
if (to.getInfo() == null) {
to.setInfo(new InfoImpl());
}
InfoImpl.merge(from.getInfo(), to.getInfo(), override);
}
// Handle @Servers
if (from.getServers() != null) {
for (Server server : from.getServers()) {
if (server != null) {
Server newServer = new ServerImpl();
ServerImpl.merge(server, newServer, true);
if (!to.getServers().contains(newServer)) {
to.addServer(newServer);
}
}
}
}
// Handle @ExternalDocumentation
if (from.getExternalDocs() != null) {
if (to.getExternalDocs() == null) {
to.setExternalDocs(new ExternalDocumentationImpl());
}
ExternalDocumentationImpl.merge(from.getExternalDocs(), to.getExternalDocs(), override);
}
// Handle @SecurityRequirement
if (from.getSecurity() != null) {
for (SecurityRequirement requirement : from.getSecurity()) {
if (requirement != null) {
SecurityRequirement newRequirement = new SecurityRequirementImpl();
SecurityRequirementImpl.merge(requirement, newRequirement);
if (!to.getSecurity().contains(newRequirement)) {
to.addSecurityRequirement(newRequirement);
}
}
}
}
// Handle @Tags
if (from.getTags() != null) {
for (Tag tag : from.getTags()) {
if (tag != null) {
if (to.getTags() == null) {
to.setTags(createList());
}
Tag newTag = new TagImpl();
TagImpl.merge(tag, newTag, override);
to.addTag(newTag);
}
}
}
// Handle @Components
ComponentsImpl.merge(from.getComponents(), to.getComponents(), override, context);
PathsImpl.merge(from.getPaths(), to.getPaths(), override);
}
use of fish.payara.microprofile.openapi.impl.model.info.InfoImpl 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);
}
Aggregations