use of fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl in project Payara by payara.
the class OpenAPIImpl method createInstance.
public static OpenAPI createInstance(AnnotationModel annotation, ApiContext context) {
OpenAPIImpl from = new OpenAPIImpl();
from.context = context;
AnnotationModel info = annotation.getValue("info", AnnotationModel.class);
if (info != null) {
from.setInfo(InfoImpl.createInstance(info));
}
AnnotationModel externalDocs = annotation.getValue("externalDocs", AnnotationModel.class);
if (externalDocs != null) {
from.setExternalDocs(ExternalDocumentationImpl.createInstance(externalDocs));
}
extractAnnotations(annotation, context, "security", SecurityRequirementImpl::createInstance, from::addSecurityRequirement);
extractAnnotations(annotation, context, "servers", ServerImpl::createInstance, from::addServer);
extractAnnotations(annotation, context, "tags", TagImpl::createInstance, from::addTag);
AnnotationModel components = annotation.getValue("components", AnnotationModel.class);
if (components != null) {
from.setComponents(ComponentsImpl.createInstance(components, context));
}
return from;
}
use of fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl in project Payara by payara.
the class OperationImpl method createInstance.
public static Operation createInstance(AnnotationModel annotation, ApiContext context) {
OperationImpl from = new OperationImpl();
from.setSummary(annotation.getValue("summary", String.class));
from.setDescription(annotation.getValue("description", String.class));
AnnotationModel externalDocs = annotation.getValue("externalDocs", AnnotationModel.class);
if (externalDocs != null) {
from.setExternalDocs(ExternalDocumentationImpl.createInstance(externalDocs));
}
from.setOperationId(annotation.getValue("operationId", String.class));
extractAnnotations(annotation, context, "parameters", ParameterImpl::createInstance, from::addParameter);
AnnotationModel requestBody = annotation.getValue("requestBody", AnnotationModel.class);
if (requestBody != null) {
from.setRequestBody(RequestBodyImpl.createInstance(requestBody, context));
}
extractAnnotations(annotation, context, "responses", "responseCode", APIResponseImpl::createInstance, from.responses::addAPIResponse);
extractAnnotations(annotation, context, "callbacks", "name", CallbackImpl::createInstance, from::addCallback);
from.setDeprecated(annotation.getValue("deprecated", Boolean.class));
extractAnnotations(annotation, context, "security", SecurityRequirementImpl::createInstance, from::addSecurityRequirement);
extractAnnotations(annotation, context, "servers", ServerImpl::createInstance, from::addServer);
from.setMethod(annotation.getValue("method", String.class));
return from;
}
use of fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl in project Payara by payara.
the class ApplicationProcessor method visitSecurityRequirement.
@Override
public void visitSecurityRequirement(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
if (element instanceof MethodModel) {
String securityRequirementName = annotation.getValue("name", String.class);
SecurityRequirement securityRequirement = SecurityRequirementImpl.createInstance(annotation, context);
if (securityRequirementName != null && !securityRequirementName.isEmpty()) {
SecurityRequirement model = new SecurityRequirementImpl();
SecurityRequirementImpl.merge(securityRequirement, model);
context.getWorkingOperation().addSecurityRequirement(model);
}
}
}
use of fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl 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.security.SecurityRequirementImpl in project Payara by payara.
the class ModelInvariantsTest method SecurityRequirementAddSchemePutsEmptyListForNullItem.
@Test
public void SecurityRequirementAddSchemePutsEmptyListForNullItem() {
SecurityRequirement requirement = new SecurityRequirementImpl();
requirement.addScheme("keyOnly");
requirement.addScheme("nullItem", (String) null);
requirement.addScheme("nullList", (List<String>) null);
List<String> keyOnly = requirement.getScheme("keyOnly");
assertNotNull(keyOnly);
assertEquals(0, keyOnly.size());
List<String> nullItem = requirement.getScheme("nullItem");
assertNotNull(nullItem);
assertEquals(0, nullItem.size());
List<String> nullList = requirement.getScheme("nullList");
assertNotNull(nullList);
assertEquals(0, nullList.size());
}
Aggregations