Search in sources :

Example 6 with AnnotatedElement

use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.

the class ApplicationProcessor method visitExternalDocumentation.

@Override
public void visitExternalDocumentation(AnnotationModel externalDocs, AnnotatedElement element, ApiContext context) {
    if (element instanceof MethodModel) {
        ExternalDocumentation newExternalDocs = new ExternalDocumentationImpl();
        ExternalDocumentationImpl.merge(ExternalDocumentationImpl.createInstance(externalDocs), newExternalDocs, true);
        if (newExternalDocs.getUrl() != null && !newExternalDocs.getUrl().isEmpty()) {
            context.getWorkingOperation().setExternalDocs(newExternalDocs);
        }
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) ExternalDocumentationImpl(fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl) ExternalDocumentation(org.eclipse.microprofile.openapi.models.ExternalDocumentation)

Example 7 with AnnotatedElement

use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.

the class ApplicationProcessor method visitTag.

@Override
public void visitTag(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
    Tag from = TagImpl.createInstance(annotation, context);
    if (element instanceof MethodModel) {
        final List<Tag> tags = new ArrayList<>();
        tags.addAll(context.getApi().getTags());
        TagImpl.merge(from, context.getWorkingOperation(), true, tags);
        context.getApi().setTags(tags);
    } else {
        Tag newTag = new TagImpl();
        TagImpl.merge(from, newTag, true);
        if (newTag.getName() != null && !newTag.getName().isEmpty()) {
            context.getApi().addTag(newTag);
        }
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) TagImpl(fish.payara.microprofile.openapi.impl.model.tags.TagImpl) ArrayList(java.util.ArrayList) Tag(org.eclipse.microprofile.openapi.models.tags.Tag)

Example 8 with AnnotatedElement

use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.

the class ApplicationProcessor method createSchema.

private Schema createSchema(Schema schema, ApiContext context, ParameterizedType type) {
    String typeName = type.getTypeName();
    List<ParameterizedType> genericTypes = type.getParameterizedTypes();
    SchemaType schemaType = ModelUtils.getSchemaType(type, context);
    if (schema == null) {
        schema = new SchemaImpl();
        schema.setType(schemaType);
    }
    // Set the subtype if it's an array (for example an array of ints)
    if (schemaType == SchemaType.ARRAY) {
        if (type.isArray()) {
            schemaType = ModelUtils.getSchemaType(type.getTypeName(), context);
            schema.setType(schemaType);
        } else if (!genericTypes.isEmpty()) {
            // should be something Iterable
            schema.setItems(createSchema(context, genericTypes.get(0)));
        }
    }
    // If the schema is an object, insert the reference
    if (schemaType == SchemaType.OBJECT) {
        if (insertObjectReference(context, schema, type.getType(), typeName)) {
            schema.setType(null);
            schema.setItems(null);
        }
    }
    if (type instanceof AnnotatedElement) {
        AnnotatedElement element = (AnnotatedElement) type;
        final AnnotationModel schemaAnnotation = element.getAnnotation(org.eclipse.microprofile.openapi.annotations.media.Schema.class.getName());
        if (schemaAnnotation != null) {
            SchemaImpl.merge(SchemaImpl.createInstance(schemaAnnotation, context), schema, false, context);
        }
    }
    return schema;
}
Also used : ParameterizedType(org.glassfish.hk2.classmodel.reflect.ParameterizedType) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Schema(org.eclipse.microprofile.openapi.models.media.Schema) AnnotatedElement(org.glassfish.hk2.classmodel.reflect.AnnotatedElement) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) SchemaType(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType)

Example 9 with AnnotatedElement

use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.

the class ApplicationProcessor method visitTags.

@Override
public void visitTags(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
    if (element instanceof MethodModel) {
        List<AnnotationModel> tags = annotation.getValue("value", List.class);
        if (tags != null) {
            for (AnnotationModel tag : tags) {
                visitTag(tag, element, context);
            }
        }
        List<String> refs = annotation.getValue("refs", List.class);
        if (refs != null) {
            for (String ref : refs) {
                if (ref != null && !ref.isEmpty()) {
                    context.getWorkingOperation().addTag(ref);
                }
            }
        }
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel)

Example 10 with AnnotatedElement

use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.

the class ApplicationProcessor method findParameterizedModelFromGenerics.

private ParameterizedInterfaceModel findParameterizedModelFromGenerics(ExtensibleType<? extends ExtensibleType> annotatedElement, Collection<ParameterizedInterfaceModel> parameterizedModels, ParameterizedType genericType) {
    if (parameterizedModels == null || parameterizedModels.isEmpty()) {
        return null;
    }
    List<String> formalParamKeys = new ArrayList<>(annotatedElement.getFormalTypeParameters().keySet());
    int i = 0;
    for (ParameterizedInterfaceModel parameterizedModel : parameterizedModels) {
        if (formalParamKeys.get(i).equals(genericType.getFormalType())) {
            return parameterizedModel;
        }
        i++;
    }
    return null;
}
Also used : ParameterizedInterfaceModel(org.glassfish.hk2.classmodel.reflect.ParameterizedInterfaceModel) ArrayList(java.util.ArrayList)

Aggregations

MethodModel (org.glassfish.hk2.classmodel.reflect.MethodModel)14 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)8 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)8 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)5 FieldModel (org.glassfish.hk2.classmodel.reflect.FieldModel)5 Schema (org.eclipse.microprofile.openapi.models.media.Schema)4 Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)4 RequestBody (org.eclipse.microprofile.openapi.models.parameters.RequestBody)3 ExternalDocumentationImpl (fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl)2 OperationImpl (fish.payara.microprofile.openapi.impl.model.OperationImpl)2 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)2 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)2 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)2 SecurityRequirementImpl (fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl)2 ServerImpl (fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)2 TagImpl (fish.payara.microprofile.openapi.impl.model.tags.TagImpl)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2