Search in sources :

Example 6 with MethodModel

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

the class ApplicationProcessor method visitParameter.

@Override
public void visitParameter(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
    Parameter matchedParam = null;
    Boolean hidden = annotation.getValue("hidden", Boolean.class);
    if (hidden != null && hidden) {
        return;
    }
    Parameter parameter = ParameterImpl.createInstance(annotation, context);
    if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
        matchedParam = findOperationParameterFor((org.glassfish.hk2.classmodel.reflect.Parameter) element, context);
    }
    if (element instanceof MethodModel) {
        matchedParam = findOperationParameterFor(parameter, (MethodModel) element, context);
    }
    if (matchedParam != null) {
        ParameterImpl.merge(parameter, matchedParam, true, context);
        // If a content was added, and a schema type exists, reconfigure the schema type
        if (matchedParam.getContent() != null && !matchedParam.getContent().getMediaTypes().isEmpty() && matchedParam.getSchema() != null && matchedParam.getSchema().getType() != null) {
            SchemaType type = matchedParam.getSchema().getType();
            matchedParam.setSchema(null);
            for (MediaType mediaType : matchedParam.getContent().getMediaTypes().values()) {
                if (mediaType.getSchema() == null) {
                    mediaType.setSchema(new SchemaImpl());
                }
                mediaType.getSchema().setType(ModelUtils.mergeProperty(mediaType.getSchema().getType(), type, false));
            }
        }
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) SchemaType(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType)

Example 7 with MethodModel

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

the class ApplicationProcessor method visitProduces.

@Override
public void visitProduces(AnnotationModel produces, AnnotatedElement element, ApiContext context) {
    if (element instanceof MethodModel && context.getWorkingOperation() != null) {
        for (APIResponse response : context.getWorkingOperation().getResponses().getAPIResponses().values()) {
            if (response != null) {
                // Find the wildcard return type
                if (response.getContent() != null && response.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD) != null) {
                    MediaType wildcardMedia = response.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD);
                    // Merge the wildcard return type with the valid response types
                    // This keeps the specific details of a reponse type that has a schema
                    List<String> mediaTypes = produces.getValue("value", List.class);
                    for (String mediaType : mediaTypes) {
                        MediaType held = response.getContent().getMediaType(getContentType(mediaType));
                        if (held == null) {
                            response.getContent().addMediaType(getContentType(mediaType), wildcardMedia);
                        } else {
                            MediaTypeImpl.merge(held, wildcardMedia, true);
                        }
                    }
                    // If there is an @Produces, remove the wildcard
                    response.getContent().removeMediaType(javax.ws.rs.core.MediaType.WILDCARD);
                }
            }
        }
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) APIResponse(org.eclipse.microprofile.openapi.models.responses.APIResponse) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType)

Example 8 with MethodModel

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

the class ApplicationProcessor method visitConsumes.

@Override
public void visitConsumes(AnnotationModel consumes, AnnotatedElement element, ApiContext context) {
    if (element instanceof MethodModel && context.getWorkingOperation() != null) {
        RequestBody requestBody = context.getWorkingOperation().getRequestBody();
        if (requestBody != null) {
            // Find the wildcard return type
            if (requestBody.getContent() != null && requestBody.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD) != null) {
                MediaType wildcardMedia = requestBody.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD);
                // Copy the wildcard return type to the valid request body types
                List<String> mediaTypes = consumes.getValue("value", List.class);
                for (String mediaType : mediaTypes) {
                    requestBody.getContent().addMediaType(getContentType(mediaType), wildcardMedia);
                }
                // If there is an @Consumes, remove the wildcard
                requestBody.getContent().removeMediaType(javax.ws.rs.core.MediaType.WILDCARD);
            }
        }
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody)

Example 9 with MethodModel

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

the class ApplicationProcessor method visitSchemaFieldOrMethod.

private void visitSchemaFieldOrMethod(AnnotationModel schemaAnnotation, AnnotatedElement fieldOrMethod, ExtensibleType<?> declaringType, String typeName, ApiContext context) {
    assert (fieldOrMethod instanceof FieldModel) || (fieldOrMethod instanceof MethodModel);
    Boolean hidden = schemaAnnotation.getValue("hidden", Boolean.class);
    if (hidden == null || !hidden) {
        // Get the schema object name
        String schemaName = ModelUtils.getSchemaName(context, fieldOrMethod);
        SchemaImpl schema = SchemaImpl.createInstance(schemaAnnotation, context);
        // Get the parent schema object name
        String parentName = null;
        AnnotationModel classSchemaAnnotation = context.getAnnotationInfo(declaringType).getAnnotation(org.eclipse.microprofile.openapi.annotations.media.Schema.class);
        if (classSchemaAnnotation != null) {
            parentName = classSchemaAnnotation.getValue("name", String.class);
        }
        if (parentName == null || parentName.isEmpty()) {
            parentName = declaringType.getSimpleName();
        }
        // Get or create the parent schema object
        final Components components = context.getApi().getComponents();
        Schema parentSchema = components.getSchemas().getOrDefault(parentName, new SchemaImpl());
        components.addSchema(parentName, parentSchema);
        Schema property = parentSchema.getProperties().getOrDefault(schemaName, new SchemaImpl());
        parentSchema.addProperty(schemaName, property);
        if (schema.isRequired()) {
            parentSchema.addRequired(schemaName);
        }
        if (property.getRef() == null) {
            property.setType(ModelUtils.getSchemaType(typeName, context));
        }
        SchemaImpl.merge(schema, property, true, context);
    }
}
Also used : Components(org.eclipse.microprofile.openapi.models.Components) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Schema(org.eclipse.microprofile.openapi.models.media.Schema) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel)

Example 10 with MethodModel

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

the class ApplicationProcessor method visitServer.

@Override
public void visitServer(AnnotationModel server, AnnotatedElement element, ApiContext context) {
    if (element instanceof MethodModel) {
        Server newServer = new ServerImpl();
        context.getWorkingOperation().addServer(newServer);
        ServerImpl.merge(ServerImpl.createInstance(server, context), newServer, true);
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) Server(org.eclipse.microprofile.openapi.models.servers.Server) ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)

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