Search in sources :

Example 1 with PathItem

use of org.eclipse.microprofile.openapi.models.PathItem in project wildfly-swarm by wildfly-swarm.

the class OpenApiAnnotationScanner method readCallbackOperations.

/**
 * Reads the CallbackOperation annotations as a PathItem.  The annotation value
 * in this case is an array of CallbackOperation annotations.
 * @param value
 */
private PathItem readCallbackOperations(AnnotationValue value) {
    if (value == null) {
        return null;
    }
    LOG.debug("Processing an array of @CallbackOperation annotations.");
    AnnotationInstance[] nestedArray = value.asNestedArray();
    PathItem pathItem = new PathItemImpl();
    for (AnnotationInstance operationAnno : nestedArray) {
        String method = JandexUtil.stringValue(operationAnno, OpenApiConstants.PROP_METHOD);
        Operation operation = readCallbackOperation(operationAnno);
        if (method == null) {
            continue;
        }
        try {
            PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(pathItem, method.toUpperCase());
            Method mutator = PropertyUtils.getWriteMethod(descriptor);
            mutator.invoke(pathItem, operation);
        } catch (Exception e) {
            LOG.error("Error reading a CallbackOperation annotation.", e);
        }
    }
    return pathItem;
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) PropertyDescriptor(java.beans.PropertyDescriptor) Operation(org.eclipse.microprofile.openapi.models.Operation) HttpMethod(org.eclipse.microprofile.openapi.models.PathItem.HttpMethod) Method(java.lang.reflect.Method) PathItemImpl(org.wildfly.swarm.microprofile.openapi.api.models.PathItemImpl) AnnotationInstance(org.jboss.jandex.AnnotationInstance) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 2 with PathItem

use of org.eclipse.microprofile.openapi.models.PathItem in project wildfly-swarm by wildfly-swarm.

the class FilterUtil method filterCallback.

/**
 * Filters the given model.
 * @param filter
 * @param model
 */
private static void filterCallback(OASFilter filter, Callback model) {
    if (model == null) {
        return;
    }
    Collection<String> keys = new ArrayList<>(model.keySet());
    for (String key : keys) {
        PathItem childModel = model.get(key);
        filterPathItem(filter, childModel);
        if (filter.filterPathItem(childModel) == null) {
            model.remove(key);
        }
    }
    filterExtensions(filter, model.getExtensions());
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) ArrayList(java.util.ArrayList)

Example 3 with PathItem

use of org.eclipse.microprofile.openapi.models.PathItem in project wildfly-swarm by wildfly-swarm.

the class FilterUtil method filterPaths.

/**
 * Filters the given model.
 * @param filter
 * @param model
 */
private static void filterPaths(OASFilter filter, Paths model) {
    if (model == null) {
        return;
    }
    Collection<String> keys = new ArrayList<>(model.keySet());
    for (String key : keys) {
        PathItem childModel = model.get(key);
        filterPathItem(filter, childModel);
        if (filter.filterPathItem(childModel) == null) {
            model.remove(key);
        }
    }
    filterExtensions(filter, model.getExtensions());
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) ArrayList(java.util.ArrayList)

Example 4 with PathItem

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

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

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