use of org.eclipse.microprofile.openapi.models.Components in project Payara by payara.
the class ComponentsImpl method createInstance.
public static Components createInstance(AnnotationModel annotation, ApiContext context) {
Components from = new ComponentsImpl();
extractAnnotations(annotation, context, "schemas", "name", SchemaImpl::createInstance, from::addSchema);
extractAnnotations(annotation, context, "responses", "name", APIResponseImpl::createInstance, from::addResponse);
extractAnnotations(annotation, context, "parameters", "name", ParameterImpl::createInstance, from::addParameter);
extractAnnotations(annotation, context, "examples", "name", ExampleImpl::createInstance, from::addExample);
extractAnnotations(annotation, context, "requestBodies", "name", RequestBodyImpl::createInstance, from::addRequestBody);
extractAnnotations(annotation, context, "securitySchemes", "securitySchemeName", SecuritySchemeImpl::createInstance, from::addSecurityScheme);
extractAnnotations(annotation, context, "links", "name", LinkImpl::createInstance, from::addLink);
extractAnnotations(annotation, context, "callbacks", "name", CallbackImpl::createInstance, from::addCallback);
HeaderImpl.createInstances(annotation, context).forEach(from::addHeader);
return from;
}
use of org.eclipse.microprofile.openapi.models.Components in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method readComponents.
/**
* Reads any Components annotations.
* @param componentsAnno
*/
private Components readComponents(AnnotationValue componentsAnno) {
if (componentsAnno == null) {
return null;
}
LOG.debug("Processing an @Components annotation.");
AnnotationInstance nested = componentsAnno.asNested();
Components components = new ComponentsImpl();
// TODO for EVERY item below, handle the case where the annotation is ref-only. then strip the ref path and use the final segment as the name
components.setCallbacks(readCallbacks(nested.value(OpenApiConstants.PROP_CALLBACKS)));
components.setExamples(readExamples(nested.value(OpenApiConstants.PROP_EXAMPLES)));
components.setHeaders(readHeaders(nested.value(OpenApiConstants.PROP_HEADERS)));
components.setLinks(readLinks(nested.value(OpenApiConstants.PROP_LINKS)));
components.setParameters(readParameters(nested.value(OpenApiConstants.PROP_PARAMETERS)));
components.setRequestBodies(readRequestBodies(nested.value(OpenApiConstants.PROP_REQUEST_BODIES)));
components.setResponses(readResponses(nested.value(OpenApiConstants.PROP_RESPONSES)));
components.setSchemas(readSchemas(nested.value(OpenApiConstants.PROP_SCHEMAS)));
components.setSecuritySchemes(readSecuritySchemes(nested.value(OpenApiConstants.PROP_SECURITY_SCHEMES)));
return components;
}
use of org.eclipse.microprofile.openapi.models.Components 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);
}
}
}
Aggregations