use of org.eclipse.microprofile.openapi.models.security.SecurityScheme 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.security.SecurityScheme in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method readSecuritySchemes.
/**
* Reads a map of SecurityScheme annotations.
* @param value
*/
private Map<String, SecurityScheme> readSecuritySchemes(AnnotationValue value) {
if (value == null) {
return null;
}
LOG.debug("Processing a map of @SecurityScheme annotations.");
Map<String, SecurityScheme> map = new LinkedHashMap<>();
AnnotationInstance[] nestedArray = value.asNestedArray();
for (AnnotationInstance nested : nestedArray) {
String name = JandexUtil.stringValue(nested, OpenApiConstants.PROP_SECURITY_SCHEME_NAME);
if (name == null && JandexUtil.isRef(nested)) {
name = JandexUtil.nameFromRef(nested);
}
if (name != null) {
map.put(name, readSecurityScheme(nested));
}
}
return map;
}
use of org.eclipse.microprofile.openapi.models.security.SecurityScheme in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method processJaxRsResourceClass.
/**
* Processing a single JAX-RS resource class (annotated with @Path).
* @param openApi
* @param resourceClass
*/
private void processJaxRsResourceClass(OpenAPIImpl openApi, ClassInfo resourceClass) {
LOG.debug("Processing a JAX-RS resource class: " + resourceClass.simpleName());
// Set the current resource path.
AnnotationInstance pathAnno = JandexUtil.getClassAnnotation(resourceClass, OpenApiConstants.DOTNAME_PATH);
this.currentResourcePath = pathAnno.value().asString();
// TODO handle the use-case where the resource class extends a base class, and the base class has jax-rs relevant methods and annotations
// Process @SecurityScheme annotations
// //////////////////////////////////////
List<AnnotationInstance> securitySchemeAnnotations = JandexUtil.getRepeatableAnnotation(resourceClass, OpenApiConstants.DOTNAME_SECURITY_SCHEME, OpenApiConstants.DOTNAME_SECURITY_SCHEMES);
for (AnnotationInstance annotation : securitySchemeAnnotations) {
String name = JandexUtil.stringValue(annotation, OpenApiConstants.PROP_SECURITY_SCHEME_NAME);
if (name == null && JandexUtil.isRef(annotation)) {
name = JandexUtil.nameFromRef(annotation);
}
if (name != null) {
SecurityScheme securityScheme = readSecurityScheme(annotation);
Components components = ModelUtil.components(openApi);
components.addSecurityScheme(name, securityScheme);
}
}
// Process tags (both declarations and references)
// //////////////////////////////////////
Set<String> tagRefs = new HashSet<>();
AnnotationInstance tagAnno = JandexUtil.getClassAnnotation(resourceClass, OpenApiConstants.DOTNAME_TAG);
if (tagAnno != null) {
if (JandexUtil.isRef(tagAnno)) {
String tagRef = JandexUtil.stringValue(tagAnno, OpenApiConstants.PROP_REF);
tagRefs.add(tagRef);
} else {
Tag tag = readTag(tagAnno);
if (tag.getName() != null) {
openApi.addTag(tag);
tagRefs.add(tag.getName());
}
}
}
AnnotationInstance tagsAnno = JandexUtil.getClassAnnotation(resourceClass, OpenApiConstants.DOTNAME_TAGS);
if (tagsAnno != null) {
AnnotationValue tagsArrayVal = tagsAnno.value();
if (tagsArrayVal != null) {
AnnotationInstance[] tagsArray = tagsArrayVal.asNestedArray();
for (AnnotationInstance ta : tagsArray) {
if (JandexUtil.isRef(ta)) {
String tagRef = JandexUtil.stringValue(ta, OpenApiConstants.PROP_REF);
tagRefs.add(tagRef);
} else {
Tag tag = readTag(ta);
if (tag.getName() != null) {
openApi.addTag(tag);
tagRefs.add(tag.getName());
}
}
}
}
List<String> listValue = JandexUtil.stringListValue(tagsAnno, OpenApiConstants.PROP_REFS);
if (listValue != null) {
tagRefs.addAll(listValue);
}
}
// //////////////////////////////////////
for (MethodInfo methodInfo : resourceClass.methods()) {
AnnotationInstance get = methodInfo.annotation(OpenApiConstants.DOTNAME_GET);
if (get != null) {
processJaxRsMethod(openApi, resourceClass, methodInfo, get, HttpMethod.GET, tagRefs);
}
AnnotationInstance put = methodInfo.annotation(OpenApiConstants.DOTNAME_PUT);
if (put != null) {
processJaxRsMethod(openApi, resourceClass, methodInfo, put, HttpMethod.PUT, tagRefs);
}
AnnotationInstance post = methodInfo.annotation(OpenApiConstants.DOTNAME_POST);
if (post != null) {
processJaxRsMethod(openApi, resourceClass, methodInfo, post, HttpMethod.POST, tagRefs);
}
AnnotationInstance delete = methodInfo.annotation(OpenApiConstants.DOTNAME_DELETE);
if (delete != null) {
processJaxRsMethod(openApi, resourceClass, methodInfo, delete, HttpMethod.DELETE, tagRefs);
}
AnnotationInstance head = methodInfo.annotation(OpenApiConstants.DOTNAME_HEAD);
if (head != null) {
processJaxRsMethod(openApi, resourceClass, methodInfo, head, HttpMethod.HEAD, tagRefs);
}
AnnotationInstance options = methodInfo.annotation(OpenApiConstants.DOTNAME_OPTIONS);
if (options != null) {
processJaxRsMethod(openApi, resourceClass, methodInfo, options, HttpMethod.OPTIONS, tagRefs);
}
}
}
use of org.eclipse.microprofile.openapi.models.security.SecurityScheme in project wildfly-swarm by wildfly-swarm.
the class OpenApiParser method readSecuritySchemes.
/**
* Reads the {@link SecurityScheme} OpenAPI nodes.
* @param node
*/
private Map<String, SecurityScheme> readSecuritySchemes(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
Map<String, SecurityScheme> models = new LinkedHashMap<>();
for (Iterator<String> fieldNames = node.fieldNames(); fieldNames.hasNext(); ) {
String fieldName = fieldNames.next();
JsonNode childNode = node.get(fieldName);
models.put(fieldName, readSecurityScheme(childNode));
}
return models;
}
Aggregations