Search in sources :

Example 21 with AnnotatedElement

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

the class ApplicationProcessor method visitAPIResponse.

@Override
public void visitAPIResponse(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
    APIResponseImpl apiResponse = APIResponseImpl.createInstance(annotation, context);
    Operation workingOperation = context.getWorkingOperation();
    // Handle exception mappers
    if (workingOperation == null) {
        if (element instanceof MethodModel && "toResponse".equals(element.getName())) {
            final MethodModel methodModel = (MethodModel) element;
            final String exceptionType = methodModel.getParameter(0).getTypeName();
            mapException(context, exceptionType, apiResponse);
        } else {
            LOGGER.warning("Unrecognised annotation position at: " + element.shortDesc());
        }
        return;
    }
    APIResponsesImpl.merge(apiResponse, workingOperation.getResponses(), true, context);
    // If an APIResponse has been processed that isn't the default
    String responseCode = apiResponse.getResponseCode();
    if (responseCode != null && !responseCode.isEmpty() && !responseCode.equals(APIResponses.DEFAULT)) {
        // If the element doesn't also contain a response mapping to the default
        AnnotationModel apiResponsesParent = element.getAnnotation(org.eclipse.microprofile.openapi.annotations.responses.APIResponses.class.getName());
        if (apiResponsesParent != null) {
            List<AnnotationModel> apiResponses = apiResponsesParent.getValue("value", List.class);
            if (apiResponses.stream().map(a -> a.getValue("responseCode", String.class)).noneMatch(code -> code == null || code.isEmpty() || code.equals(APIResponses.DEFAULT))) {
                // Then remove the default response
                workingOperation.getResponses().removeAPIResponse(APIResponses.DEFAULT);
            }
        } else {
            workingOperation.getResponses().removeAPIResponse(APIResponses.DEFAULT);
        }
    }
}
Also used : RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl) Components(org.eclipse.microprofile.openapi.models.Components) Arrays(java.util.Arrays) ExtensibleImpl(fish.payara.microprofile.openapi.impl.model.ExtensibleImpl) ModelUtils.isVoid(fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isVoid) PathItem(org.eclipse.microprofile.openapi.models.PathItem) ExtensibleType(org.glassfish.hk2.classmodel.reflect.ExtensibleType) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) ParameterizedType(org.glassfish.hk2.classmodel.reflect.ParameterizedType) DefaultValue(javax.ws.rs.DefaultValue) MediaTypeImpl(fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl) Method(java.lang.reflect.Method) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) Collection(java.util.Collection) AnnotatedElement(org.glassfish.hk2.classmodel.reflect.AnnotatedElement) Set(java.util.Set) WARNING(java.util.logging.Level.WARNING) OpenAPIImpl(fish.payara.microprofile.openapi.impl.model.OpenAPIImpl) ApiVisitor(fish.payara.microprofile.openapi.api.visitor.ApiVisitor) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) List(java.util.List) ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl) TagImpl(fish.payara.microprofile.openapi.impl.model.tags.TagImpl) SchemaType(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl) ExternalDocumentation(org.eclipse.microprofile.openapi.models.ExternalDocumentation) Entry(java.util.Map.Entry) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Server(org.eclipse.microprofile.openapi.models.servers.Server) OASProcessor(fish.payara.microprofile.openapi.api.processor.OASProcessor) OpenApiConfiguration(fish.payara.microprofile.openapi.impl.config.OpenApiConfiguration) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) SecuritySchemeImpl(fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement) APIResponse(org.eclipse.microprofile.openapi.models.responses.APIResponse) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel) ModelUtils(fish.payara.microprofile.openapi.impl.model.util.ModelUtils) HttpMethod(javax.ws.rs.HttpMethod) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) SEVERE(java.util.logging.Level.SEVERE) SecurityRequirementImpl(fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl) Operation(org.eclipse.microprofile.openapi.models.Operation) ParameterizedInterfaceModel(org.glassfish.hk2.classmodel.reflect.ParameterizedInterfaceModel) Schema(org.eclipse.microprofile.openapi.models.media.Schema) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) Status(javax.ws.rs.core.Response.Status) FINE(java.util.logging.Level.FINE) Callback(org.eclipse.microprofile.openapi.models.callbacks.Callback) Types(org.glassfish.hk2.classmodel.reflect.Types) FormParam(javax.ws.rs.FormParam) OpenApiWalker(fish.payara.microprofile.openapi.impl.visitor.OpenApiWalker) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) CallbackImpl(fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl) APIResponsesImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponsesImpl) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) EnumType(org.glassfish.hk2.classmodel.reflect.EnumType) ParameterImpl(fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) ExternalDocumentationImpl(fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl) Reference(org.eclipse.microprofile.openapi.models.Reference) ApiContext(fish.payara.microprofile.openapi.api.visitor.ApiContext) Collections(java.util.Collections) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) ClassModel(org.glassfish.hk2.classmodel.reflect.ClassModel) In(org.eclipse.microprofile.openapi.models.parameters.Parameter.In) Type(org.glassfish.hk2.classmodel.reflect.Type) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl) Operation(org.eclipse.microprofile.openapi.models.Operation)

Example 22 with AnnotatedElement

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

the class ApplicationProcessor method visitCallback.

@Override
public void visitCallback(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
    if (element instanceof MethodModel) {
        String name = annotation.getValue("name", String.class);
        Callback callbackModel = context.getWorkingOperation().getCallbacks().getOrDefault(name, new CallbackImpl());
        context.getWorkingOperation().addCallback(name, callbackModel);
        CallbackImpl.merge(CallbackImpl.createInstance(annotation, context), callbackModel, true, context);
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) Callback(org.eclipse.microprofile.openapi.models.callbacks.Callback) CallbackImpl(fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)

Example 23 with AnnotatedElement

use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement 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)

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