Search in sources :

Example 1 with OperationImpl

use of fish.payara.microprofile.openapi.impl.model.OperationImpl in project Payara by payara.

the class ApplicationProcessor method visitDELETE.

@Override
public void visitDELETE(AnnotationModel delete, MethodModel element, ApiContext context) {
    if (context.getPath() == null) {
        return;
    }
    // Get or create the path item
    PathItem pathItem = context.getApi().getPaths().getPathItems().getOrDefault(context.getPath(), new PathItemImpl());
    context.getApi().getPaths().addPathItem(context.getPath(), pathItem);
    OperationImpl operation = new OperationImpl();
    pathItem.setDELETE(operation);
    operation.setOperationId(element.getName());
    operation.setMethod(HttpMethod.DELETE);
    // Add the default request
    insertDefaultRequestBody(context, operation, element);
    // Add the default response
    insertDefaultResponse(context, operation, element);
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl)

Example 2 with OperationImpl

use of fish.payara.microprofile.openapi.impl.model.OperationImpl in project Payara by payara.

the class ApplicationProcessor method visitAPIResponseSchema.

@Override
public void visitAPIResponseSchema(AnnotationModel apiResponseSchema, AnnotatedElement element, ApiContext context) {
    final APIResponseImpl response = APIResponseImpl.createInstance(apiResponseSchema, context);
    final OperationImpl operation = (OperationImpl) context.getWorkingOperation();
    // Handle exception mappers
    if (operation == null) {
        if (element instanceof MethodModel && "toResponse".equals(element.getName())) {
            final MethodModel methodModel = (MethodModel) element;
            final String exceptionType = methodModel.getParameter(0).getTypeName();
            mapException(context, exceptionType, response);
        } else {
            LOGGER.warning("Unrecognised annotation position at: " + element.shortDesc());
        }
        return;
    }
    // If response code hasn't been specified
    String responseCode = response.getResponseCode();
    if (responseCode == null || responseCode.isEmpty()) {
        assert element instanceof MethodModel;
        final MethodModel method = (MethodModel) element;
        if (isVoid(method.getReturnType())) {
            if (HttpMethod.POST.equals(operation.getMethod())) {
                responseCode = "201";
            } else if (Arrays.asList(method.getArgumentTypes()).contains("javax.ws.rs.container.AsyncResponse")) {
                responseCode = "200";
            } else {
                responseCode = "204";
            }
        } else {
            responseCode = "200";
        }
    }
    response.setResponseCode(responseCode);
    // If the response description hasn't been specified
    final String responseDescription = response.getDescription();
    if (responseDescription == null || responseDescription.isEmpty()) {
        try {
            final int statusInt = Integer.parseInt(responseCode);
            final Status status = Status.fromStatusCode(statusInt);
            if (status != null) {
                response.setDescription(status.getReasonPhrase());
            }
        } catch (NumberFormatException ex) {
            LOGGER.log(Level.FINE, "Unrecognised status code, description will be empty", ex);
        }
    }
    final APIResponses responses = operation.getResponses();
    // Remove the default response
    final APIResponse defaultResponse = responses.getAPIResponse(APIResponses.DEFAULT);
    if (defaultResponse != null) {
        responses.removeAPIResponse(APIResponses.DEFAULT);
        responses.addAPIResponse(responseCode, defaultResponse);
    }
    // Add the generated response
    APIResponsesImpl.merge(response, responses, true, context);
}
Also used : Status(javax.ws.rs.core.Response.Status) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) APIResponse(org.eclipse.microprofile.openapi.models.responses.APIResponse) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)

Example 3 with OperationImpl

use of fish.payara.microprofile.openapi.impl.model.OperationImpl in project Payara by payara.

the class ApplicationProcessor method visitPUT.

@Override
public void visitPUT(AnnotationModel put, MethodModel element, ApiContext context) {
    if (context.getPath() == null) {
        return;
    }
    // Get or create the path item
    PathItem pathItem = context.getApi().getPaths().getPathItems().getOrDefault(context.getPath(), new PathItemImpl());
    context.getApi().getPaths().addPathItem(context.getPath(), pathItem);
    OperationImpl operation = new OperationImpl();
    pathItem.setPUT(operation);
    operation.setOperationId(element.getName());
    operation.setMethod(HttpMethod.PUT);
    // Add the default request
    insertDefaultRequestBody(context, operation, element);
    // Add the default response
    insertDefaultResponse(context, operation, element);
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl)

Example 4 with OperationImpl

use of fish.payara.microprofile.openapi.impl.model.OperationImpl in project Payara by payara.

the class ApplicationProcessor method visitOPTIONS.

@Override
public void visitOPTIONS(AnnotationModel options, MethodModel element, ApiContext context) {
    if (context.getPath() == null) {
        return;
    }
    // Get or create the path item
    PathItem pathItem = context.getApi().getPaths().getPathItems().getOrDefault(context.getPath(), new PathItemImpl());
    context.getApi().getPaths().addPathItem(context.getPath(), pathItem);
    OperationImpl operation = new OperationImpl();
    pathItem.setOPTIONS(operation);
    operation.setOperationId(element.getName());
    operation.setMethod(HttpMethod.OPTIONS);
    // Add the default request
    insertDefaultRequestBody(context, operation, element);
    // Add the default response
    insertDefaultResponse(context, operation, element);
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl)

Example 5 with OperationImpl

use of fish.payara.microprofile.openapi.impl.model.OperationImpl in project Payara by payara.

the class ApplicationProcessor method visitGET.

// JAX-RS method handlers
@Override
public void visitGET(AnnotationModel get, MethodModel element, ApiContext context) {
    if (context.getPath() == null) {
        return;
    }
    // Get or create the path item
    PathItem pathItem = context.getApi().getPaths().getPathItems().getOrDefault(context.getPath(), new PathItemImpl());
    context.getApi().getPaths().addPathItem(context.getPath(), pathItem);
    OperationImpl operation = new OperationImpl();
    pathItem.setGET(operation);
    operation.setOperationId(element.getName());
    operation.setMethod(HttpMethod.GET);
    // Add the default request
    insertDefaultRequestBody(context, operation, element);
    // Add the default response
    insertDefaultResponse(context, operation, element);
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl)

Aggregations

OperationImpl (fish.payara.microprofile.openapi.impl.model.OperationImpl)9 PathItemImpl (fish.payara.microprofile.openapi.impl.model.PathItemImpl)7 PathItem (org.eclipse.microprofile.openapi.models.PathItem)7 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)1 ModelUtils.getHttpMethod (fish.payara.microprofile.openapi.impl.model.util.ModelUtils.getHttpMethod)1 ModelUtils.getOrCreateOperation (fish.payara.microprofile.openapi.impl.model.util.ModelUtils.getOrCreateOperation)1 Status (javax.ws.rs.core.Response.Status)1 Operation (org.eclipse.microprofile.openapi.models.Operation)1 HttpMethod (org.eclipse.microprofile.openapi.models.PathItem.HttpMethod)1 APIResponse (org.eclipse.microprofile.openapi.models.responses.APIResponse)1 APIResponses (org.eclipse.microprofile.openapi.models.responses.APIResponses)1 MethodModel (org.glassfish.hk2.classmodel.reflect.MethodModel)1