Search in sources :

Example 1 with Operation

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

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

the class ApplicationProcessor method addParameter.

private static void addParameter(AnnotatedElement element, ApiContext context, String name, In in, Boolean required) {
    Boolean hidden = false;
    AnnotationModel paramAnnotation = element.getAnnotation(org.eclipse.microprofile.openapi.annotations.parameters.Parameter.class.getName());
    if (paramAnnotation != null) {
        hidden = paramAnnotation.getValue("hidden", Boolean.class);
    }
    if (hidden != null && hidden) {
        return;
    }
    Parameter newParameter = new ParameterImpl();
    newParameter.setName(name);
    newParameter.setIn(in);
    newParameter.setRequired(required);
    SchemaImpl schema = new SchemaImpl();
    String defaultValue = getDefaultValueIfPresent(element);
    if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
        org.glassfish.hk2.classmodel.reflect.Parameter parameter = (org.glassfish.hk2.classmodel.reflect.Parameter) element;
        schema.setType(ModelUtils.getSchemaType(parameter.getTypeName(), context));
    } else {
        FieldModel field = (FieldModel) element;
        schema.setType(ModelUtils.getSchemaType(field.getTypeName(), context));
    }
    if (schema.getType() == SchemaType.ARRAY) {
        schema.setItems(getArraySchema(element, context));
        if (defaultValue != null) {
            schema.getItems().setDefaultValue(defaultValue);
        }
    } else if (defaultValue != null) {
        schema.setDefaultValue(defaultValue);
    }
    newParameter.setSchema(schema);
    final Operation workingOperation = context.getWorkingOperation();
    if (workingOperation != null) {
        for (Parameter parameter : workingOperation.getParameters()) {
            final String parameterName = parameter.getName();
            if (parameterName != null && parameterName.equals(newParameter.getName())) {
                ParameterImpl.merge(newParameter, parameter, false, context);
                return;
            }
        }
        workingOperation.addParameter(newParameter);
    } else {
        LOGGER.log(SEVERE, "Couldn''t add {0} parameter, \"{1}\" to the OpenAPI Document. This is usually caused by declaring parameter under a method with an unsupported annotation.", new Object[] { newParameter.getIn(), newParameter.getName() });
    }
}
Also used : Operation(org.eclipse.microprofile.openapi.models.Operation) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) ParameterImpl(fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel)

Example 3 with Operation

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

the class ApplicationProcessor method visitParameters.

@Override
public void visitParameters(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
    List<AnnotationModel> parameters = annotation.getValue("value", List.class);
    if (parameters != null) {
        for (AnnotationModel paramAnnotation : parameters) {
            final Parameter parameter = ParameterImpl.createInstance(paramAnnotation, context);
            final Operation workingOperation = context.getWorkingOperation();
            if (workingOperation != null) {
                workingOperation.addParameter(parameter);
            }
        }
    }
}
Also used : AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) Operation(org.eclipse.microprofile.openapi.models.Operation)

Example 4 with Operation

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

the class ApplicationProcessor method visitFormParam.

@Override
public void visitFormParam(AnnotationModel param, AnnotatedElement element, ApiContext context) {
    // Find the aggregate schema type of all the parameters
    SchemaType formSchemaType = null;
    if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
        List<org.glassfish.hk2.classmodel.reflect.Parameter> parameters = ((org.glassfish.hk2.classmodel.reflect.Parameter) element).getMethod().getParameters();
        for (org.glassfish.hk2.classmodel.reflect.Parameter methodParam : parameters) {
            if (methodParam.getAnnotation(FormParam.class.getName()) != null) {
                formSchemaType = ModelUtils.getParentSchemaType(formSchemaType, ModelUtils.getSchemaType(methodParam, context));
            }
        }
    }
    final Operation workingOperation = context.getWorkingOperation();
    if (workingOperation != null) {
        // If there's no request body, fill out a new one right down to the schema
        if (workingOperation.getRequestBody() == null) {
            workingOperation.setRequestBody(new RequestBodyImpl().content(new ContentImpl().addMediaType(javax.ws.rs.core.MediaType.WILDCARD, new MediaTypeImpl().schema(new SchemaImpl()))));
        }
        for (MediaType mediaType : workingOperation.getRequestBody().getContent().getMediaTypes().values()) {
            final Schema schema = mediaType.getSchema();
            if (schema != null) {
                schema.setType(formSchemaType);
            }
        }
    }
}
Also used : Schema(org.eclipse.microprofile.openapi.models.media.Schema) RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl) Operation(org.eclipse.microprofile.openapi.models.Operation) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) SchemaType(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) MediaTypeImpl(fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType)

Example 5 with Operation

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

the class CallbackImpl method merge.

public static void merge(Callback from, Callback to, boolean override, ApiContext context) {
    if (from == null) {
        return;
    }
    if (from.getRef() != null && !from.getRef().isEmpty()) {
        applyReference(to, from.getRef());
        return;
    }
    if (from instanceof CallbackImpl) {
        CallbackImpl fromImpl = (CallbackImpl) from;
        String urlExpression = fromImpl.getUrlExpression();
        if (urlExpression != null && !urlExpression.isEmpty()) {
            PathItem pathItem = to.getPathItems().getOrDefault(urlExpression, new PathItemImpl());
            to.addPathItem(urlExpression, pathItem);
            if (fromImpl.getOperations() != null) {
                for (Operation callbackOperation : fromImpl.getOperations()) {
                    applyCallbackOperationAnnotation(pathItem, callbackOperation, override, context);
                }
            }
        }
    }
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) Operation(org.eclipse.microprofile.openapi.models.Operation) ModelUtils.getOrCreateOperation(fish.payara.microprofile.openapi.impl.model.util.ModelUtils.getOrCreateOperation) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl)

Aggregations

Operation (org.eclipse.microprofile.openapi.models.Operation)14 PathItem (org.eclipse.microprofile.openapi.models.PathItem)8 Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)7 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)5 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)5 Schema (org.eclipse.microprofile.openapi.models.media.Schema)5 PathItemImpl (fish.payara.microprofile.openapi.impl.model.PathItemImpl)4 ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)4 MediaTypeImpl (fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl)4 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)4 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)4 ServerImpl (fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)4 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)4 RequestBody (org.eclipse.microprofile.openapi.models.parameters.RequestBody)4 APIResponse (org.eclipse.microprofile.openapi.models.responses.APIResponse)4 APIResponses (org.eclipse.microprofile.openapi.models.responses.APIResponses)4 SecurityRequirement (org.eclipse.microprofile.openapi.models.security.SecurityRequirement)4 Server (org.eclipse.microprofile.openapi.models.servers.Server)4 Tag (org.eclipse.microprofile.openapi.models.tags.Tag)4 OperationImpl (fish.payara.microprofile.openapi.impl.model.OperationImpl)3