Search in sources :

Example 6 with Components

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;
}
Also used : Components(org.eclipse.microprofile.openapi.models.Components) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) CallbackImpl(fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl) ParameterImpl(fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl) SecuritySchemeImpl(fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl) LinkImpl(fish.payara.microprofile.openapi.impl.model.links.LinkImpl) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl) RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl) ExampleImpl(fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)

Example 7 with Components

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;
}
Also used : Components(org.eclipse.microprofile.openapi.models.Components) ComponentsImpl(org.wildfly.swarm.microprofile.openapi.api.models.ComponentsImpl) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Example 8 with 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);
        }
    }
}
Also used : Components(org.eclipse.microprofile.openapi.models.Components) AnnotationValue(org.jboss.jandex.AnnotationValue) MethodInfo(org.jboss.jandex.MethodInfo) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) AnnotationInstance(org.jboss.jandex.AnnotationInstance) HashSet(java.util.HashSet)

Aggregations

Components (org.eclipse.microprofile.openapi.models.Components)8 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)4 Schema (org.eclipse.microprofile.openapi.models.media.Schema)3 SecurityScheme (org.eclipse.microprofile.openapi.models.security.SecurityScheme)3 AnnotationInstance (org.jboss.jandex.AnnotationInstance)3 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)2 ExampleImpl (fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)2 LinkImpl (fish.payara.microprofile.openapi.impl.model.links.LinkImpl)2 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)2 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)2 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)2 SecuritySchemeImpl (fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl)2 Tag (org.eclipse.microprofile.openapi.models.tags.Tag)2 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)2 FieldModel (org.glassfish.hk2.classmodel.reflect.FieldModel)2 HeaderImpl (fish.payara.microprofile.openapi.impl.model.headers.HeaderImpl)1 ContactImpl (fish.payara.microprofile.openapi.impl.model.info.ContactImpl)1 InfoImpl (fish.payara.microprofile.openapi.impl.model.info.InfoImpl)1 LicenseImpl (fish.payara.microprofile.openapi.impl.model.info.LicenseImpl)1 ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)1