Search in sources :

Example 16 with MethodModel

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

the class ApplicationProcessor method visitRequestBodySchema.

@Override
public void visitRequestBodySchema(AnnotationModel requestBodySchema, AnnotatedElement element, ApiContext context) {
    if (element instanceof MethodModel || element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
        final RequestBody currentRequestBody = context.getWorkingOperation().getRequestBody();
        if (currentRequestBody != null) {
            final String implementationClass = requestBodySchema.getValue("value", String.class);
            final SchemaImpl schema = SchemaImpl.fromImplementation(implementationClass, context);
            for (MediaType mediaType : currentRequestBody.getContent().getMediaTypes().values()) {
                mediaType.setSchema(schema);
            }
        }
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody)

Example 17 with MethodModel

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

the class AnnotationInfo method init.

private void init(ExtensibleType<? extends ExtensibleType> type) {
    // recurse first so that re-stated annotations "override"
    ExtensibleType<? extends ExtensibleType> supertype = type.getParent();
    if (supertype != null) {
        init(supertype);
    }
    for (InterfaceModel implementedInterface : type.getInterfaces()) {
        if (implementedInterface != null && implementedInterface != type) {
            init(implementedInterface);
        }
    }
    // collect annotations
    putAll(type.getAnnotations(), typeAnnotations);
    if (type instanceof ClassModel) {
        for (FieldModel field : ((ClassModel) type).getFields()) {
            putAll(field.getAnnotations(), fieldAnnotations.computeIfAbsent(field.getName(), key -> new ConcurrentHashMap<>()));
        }
    }
    for (MethodModel method : type.getMethods()) {
        putAll(method.getAnnotations(), methodAnnotations.computeIfAbsent(getSignature(method), key -> new ConcurrentHashMap<>()));
        for (Parameter parameter : method.getParameters()) {
            putAll(parameter.getAnnotations(), methodParameterAnnotations.computeIfAbsent(getIdentifier(parameter), key -> new ConcurrentHashMap<>()));
        }
    }
}
Also used : InterfaceModel(org.glassfish.hk2.classmodel.reflect.InterfaceModel) Collection(java.util.Collection) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AnnotatedElement(org.glassfish.hk2.classmodel.reflect.AnnotatedElement) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel) Parameter(org.glassfish.hk2.classmodel.reflect.Parameter) Field(java.lang.reflect.Field) ExtensibleType(org.glassfish.hk2.classmodel.reflect.ExtensibleType) Map(java.util.Map) Annotation(java.lang.annotation.Annotation) Method(java.lang.reflect.Method) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) ClassModel(org.glassfish.hk2.classmodel.reflect.ClassModel) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) InterfaceModel(org.glassfish.hk2.classmodel.reflect.InterfaceModel) ClassModel(org.glassfish.hk2.classmodel.reflect.ClassModel) Parameter(org.glassfish.hk2.classmodel.reflect.Parameter) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 18 with MethodModel

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

the class OpenApiWalker method processAnnotation.

@SuppressWarnings("unchecked")
public final void processAnnotation(ClassModel annotatedClass, ApiVisitor visitor) {
    AnnotationInfo annotations = context.getAnnotationInfo(annotatedClass);
    processAnnotation((E) annotatedClass, annotations, visitor, new OpenApiContext(context, annotatedClass));
    for (final MethodModel method : annotatedClass.getMethods()) {
        processAnnotation((E) method, annotations, visitor, new OpenApiContext(context, method));
    }
    for (final FieldModel field : annotatedClass.getFields()) {
        processAnnotation((E) field, annotations, visitor, new OpenApiContext(context, field));
    }
    for (final MethodModel method : annotatedClass.getMethods()) {
        for (org.glassfish.hk2.classmodel.reflect.Parameter parameter : method.getParameters()) {
            processAnnotation((E) parameter, annotations, visitor, new OpenApiContext(context, method));
        }
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel)

Example 19 with MethodModel

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

the class OpenApiWalker method processAnnotation.

private void processAnnotation(E element, AnnotationInfo annotations, ApiVisitor visitor, OpenApiContext context) {
    for (Class<? extends Annotation> annotationClass : getAnnotationVisitor(visitor).keySet()) {
        VisitorFunction<AnnotationModel, E> annotationFunction = getAnnotationVisitor(visitor).get(annotationClass);
        Class<? extends Annotation> alternative = getAnnotationAlternatives().get(annotationClass);
        // Check the element
        if (annotations.isAnnotationPresent(annotationClass, element)) {
            if (element instanceof FieldModel && (annotationClass == HeaderParam.class || annotationClass == CookieParam.class || annotationClass == PathParam.class || annotationClass == QueryParam.class)) {
                FieldModel field = (FieldModel) element;
                // NB. if fields are annotated as Param all methods have it
                for (MethodModel method : field.getDeclaringType().getMethods()) {
                    OpenApiContext methodContext = new OpenApiContext(context, method);
                    if (methodContext.getWorkingOperation() != null) {
                        annotationFunction.apply(annotations.getAnnotation(annotationClass, element), element, methodContext);
                    }
                }
            } else {
                annotationFunction.apply(annotations.getAnnotation(annotationClass, element), element, context);
            }
        } else if (element instanceof MethodModel && annotations.isAnnotationPresent(annotationClass) && (alternative == null || !annotations.isAnnotationPresent(alternative, element))) {
            // If the method isn't annotated, inherit the class annotation
            if (context.getPath() != null) {
                annotationFunction.apply(annotations.getAnnotation(annotationClass), element, context);
            }
        }
    }
}
Also used : CookieParam(javax.ws.rs.CookieParam) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) HeaderParam(javax.ws.rs.HeaderParam) DELETE(javax.ws.rs.DELETE) QueryParam(javax.ws.rs.QueryParam) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel)

Aggregations

MethodModel (org.glassfish.hk2.classmodel.reflect.MethodModel)18 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)7 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)7 FieldModel (org.glassfish.hk2.classmodel.reflect.FieldModel)7 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)5 RequestBody (org.eclipse.microprofile.openapi.models.parameters.RequestBody)5 ExtensibleType (org.glassfish.hk2.classmodel.reflect.ExtensibleType)4 ExternalDocumentationImpl (fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl)3 OperationImpl (fish.payara.microprofile.openapi.impl.model.OperationImpl)3 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)3 MediaTypeImpl (fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl)3 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)3 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)3 SecurityRequirementImpl (fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl)3 ServerImpl (fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)3 TagImpl (fish.payara.microprofile.openapi.impl.model.tags.TagImpl)3 Method (java.lang.reflect.Method)3 Collection (java.util.Collection)3 Components (org.eclipse.microprofile.openapi.models.Components)3 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)3