Search in sources :

Example 11 with PathItem

use of org.eclipse.microprofile.openapi.models.PathItem in project Payara by payara.

the class ApplicationProcessor method mapException.

/**
 * When an exception mapper is encountered, register the mapped response and
 * find any operations already parsed that this exception mapper is applicable
 * to
 */
private void mapException(ApiContext context, String exceptionType, APIResponseImpl exceptionResponse) {
    // Don't allow null responses
    if (exceptionResponse.getDescription() == null || exceptionResponse.getDescription().isEmpty()) {
        exceptionResponse.setDescription(ModelUtils.getSimpleName(exceptionType));
    }
    context.addMappedExceptionResponse(exceptionType, exceptionResponse);
    final String exceptionStatus = exceptionResponse.getResponseCode();
    if (exceptionStatus != null) {
        for (PathItem path : context.getApi().getPaths().getPathItems().values()) {
            for (Operation operation : path.getOperations().values()) {
                if (((OperationImpl) operation).getExceptionTypes().contains(exceptionType)) {
                    operation.getResponses().addAPIResponse(exceptionStatus, exceptionResponse);
                }
            }
        }
    } else {
        LOGGER.fine("Failed to add mapped response as no response code was provided");
    }
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) Operation(org.eclipse.microprofile.openapi.models.Operation)

Example 12 with PathItem

use of org.eclipse.microprofile.openapi.models.PathItem 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)

Example 13 with PathItem

use of org.eclipse.microprofile.openapi.models.PathItem in project Payara by payara.

the class ApplicationProcessor method visitPATCH.

@Override
public void visitPATCH(AnnotationModel patch, 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.setPATCH(operation);
    operation.setOperationId(element.getName());
    operation.setMethod(HttpMethod.PATCH);
    // 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 14 with PathItem

use of org.eclipse.microprofile.openapi.models.PathItem in project Payara by payara.

the class ApplicationProcessor method visitHEAD.

@Override
public void visitHEAD(AnnotationModel head, 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.setHEAD(operation);
    operation.setOperationId(element.getName());
    operation.setMethod(HttpMethod.HEAD);
    // 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 15 with PathItem

use of org.eclipse.microprofile.openapi.models.PathItem in project Payara by payara.

the class ApplicationProcessor method visitPOST.

@Override
public void visitPOST(AnnotationModel post, 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.setPOST(operation);
    operation.setOperationId(element.getName());
    operation.setMethod(HttpMethod.POST);
    // 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

PathItem (org.eclipse.microprofile.openapi.models.PathItem)20 PathItemImpl (fish.payara.microprofile.openapi.impl.model.PathItemImpl)10 OperationImpl (fish.payara.microprofile.openapi.impl.model.OperationImpl)7 Operation (org.eclipse.microprofile.openapi.models.Operation)6 ServerImpl (fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)3 HashSet (java.util.HashSet)3 Server (org.eclipse.microprofile.openapi.models.servers.Server)3 InfoImpl (fish.payara.microprofile.openapi.impl.model.info.InfoImpl)2 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)2 ArrayList (java.util.ArrayList)2 Paths (org.eclipse.microprofile.openapi.models.Paths)2 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)2 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)2 Schema (org.eclipse.microprofile.openapi.models.media.Schema)2 Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)2 RequestBody (org.eclipse.microprofile.openapi.models.parameters.RequestBody)2 APIResponse (org.eclipse.microprofile.openapi.models.responses.APIResponse)2 APIResponses (org.eclipse.microprofile.openapi.models.responses.APIResponses)2 SecurityRequirement (org.eclipse.microprofile.openapi.models.security.SecurityRequirement)2 Tag (org.eclipse.microprofile.openapi.models.tags.Tag)2