Search in sources :

Example 1 with Parameter

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

the class OpenApiParser method readParameters.

/**
 * Reads the {@link Parameter} OpenAPI nodes.
 * @param node
 */
private Map<String, Parameter> readParameters(JsonNode node) {
    if (node == null || !node.isObject()) {
        return null;
    }
    Map<String, Parameter> models = new LinkedHashMap<>();
    for (Iterator<String> fieldNames = node.fieldNames(); fieldNames.hasNext(); ) {
        String fieldName = fieldNames.next();
        JsonNode childNode = node.get(fieldName);
        models.put(fieldName, readParameter(childNode));
    }
    return models;
}
Also used : Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) JsonNode(com.fasterxml.jackson.databind.JsonNode) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Parameter

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

the class OpenApiParser method readParameter.

/**
 * Reads a {@link Parameter} OpenAPI node.
 * @param node
 */
private Parameter readParameter(JsonNode node) {
    if (node == null || !node.isObject()) {
        return null;
    }
    Parameter model = new ParameterImpl();
    model.setRef(JsonUtil.stringProperty(node, OpenApiConstants.PROP_$REF));
    model.setName(JsonUtil.stringProperty(node, OpenApiConstants.PROP_NAME));
    model.setIn(readParameterIn(node.get(OpenApiConstants.PROP_IN)));
    model.setDescription(JsonUtil.stringProperty(node, OpenApiConstants.PROP_DESCRIPTION));
    model.setRequired(JsonUtil.booleanProperty(node, OpenApiConstants.PROP_REQUIRED));
    model.setSchema(readSchema(node.get(OpenApiConstants.PROP_SCHEMA)));
    model.setAllowEmptyValue(JsonUtil.booleanProperty(node, OpenApiConstants.PROP_ALLOW_EMPTY_VALUE));
    model.setDeprecated(JsonUtil.booleanProperty(node, OpenApiConstants.PROP_DEPRECATED));
    model.setStyle(readParameterStyle(node.get(OpenApiConstants.PROP_STYLE)));
    model.setExplode(JsonUtil.booleanProperty(node, OpenApiConstants.PROP_EXPLODE));
    model.setAllowReserved(JsonUtil.booleanProperty(node, OpenApiConstants.PROP_ALLOW_RESERVED));
    model.setExample(readObject(node.get(OpenApiConstants.PROP_EXAMPLE)));
    model.setExamples(readExamples(node.get(OpenApiConstants.PROP_EXAMPLES)));
    model.setContent(readContent(node.get(OpenApiConstants.PROP_CONTENT)));
    readExtensions(node, model);
    return model;
}
Also used : ParameterImpl(org.wildfly.swarm.microprofile.openapi.api.models.parameters.ParameterImpl) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter)

Example 3 with Parameter

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

the class FilterUtil method filterParameterList.

/**
 * Filters the given models.
 * @param filter
 * @param models
 */
private static void filterParameterList(OASFilter filter, List<Parameter> models) {
    if (models == null) {
        return;
    }
    ListIterator<Parameter> iterator = models.listIterator();
    while (iterator.hasNext()) {
        Parameter model = iterator.next();
        filterParameter(filter, model);
        if (filter.filterParameter(model) == null) {
            iterator.remove();
        }
    }
}
Also used : Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter)

Example 4 with Parameter

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

the class ApplicationProcessor method getArraySchema.

private static SchemaImpl getArraySchema(AnnotatedElement element, ApiContext context) {
    SchemaImpl arraySchema = new SchemaImpl();
    List<ParameterizedType> parameterizedType;
    if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
        org.glassfish.hk2.classmodel.reflect.Parameter parameter = (org.glassfish.hk2.classmodel.reflect.Parameter) element;
        parameterizedType = parameter.getParameterizedTypes();
    } else {
        FieldModel field = (FieldModel) element;
        parameterizedType = field.getParameterizedTypes();
    }
    arraySchema.setType(ModelUtils.getSchemaType(parameterizedType.get(0).getTypeName(), context));
    return arraySchema;
}
Also used : ParameterizedType(org.glassfish.hk2.classmodel.reflect.ParameterizedType) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel)

Example 5 with Parameter

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

Aggregations

Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)19 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)7 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)5 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)5 Operation (org.eclipse.microprofile.openapi.models.Operation)5 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)5 Schema (org.eclipse.microprofile.openapi.models.media.Schema)5 APIResponse (org.eclipse.microprofile.openapi.models.responses.APIResponse)5 ArrayList (java.util.ArrayList)4 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)4 RequestBody (org.eclipse.microprofile.openapi.models.parameters.RequestBody)4 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)3 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)3 SecuritySchemeImpl (fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl)3 LinkedHashMap (java.util.LinkedHashMap)3 PathItem (org.eclipse.microprofile.openapi.models.PathItem)3 In (org.eclipse.microprofile.openapi.models.parameters.Parameter.In)3 APIResponses (org.eclipse.microprofile.openapi.models.responses.APIResponses)3 SecurityRequirement (org.eclipse.microprofile.openapi.models.security.SecurityRequirement)3 SecurityScheme (org.eclipse.microprofile.openapi.models.security.SecurityScheme)3