Search in sources :

Example 6 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 7 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 8 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 9 with Parameter

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

the class ApplicationProcessor method findOperationParameterFor.

private static Parameter findOperationParameterFor(Parameter parameter, MethodModel annotated, ApiContext context) {
    String name = parameter.getName();
    // If the parameter reference is valid
    if (name != null && !name.isEmpty()) {
        // Get all parameters with the same name
        List<org.glassfish.hk2.classmodel.reflect.Parameter> matchingMethodParameters = annotated.getParameters().stream().filter(x -> name.equals(ModelUtils.getParameterName(context, x))).collect(Collectors.toList());
        // If there is more than one match, filter it further
        In in = parameter.getIn();
        if (matchingMethodParameters.size() > 1 && in != null) {
            // Remove all parameters of the wrong input type
            matchingMethodParameters.removeIf(x -> ModelUtils.getParameterType(context, x) != In.valueOf(in.name()));
        }
        if (matchingMethodParameters.isEmpty()) {
            return null;
        }
        // If there's only one matching parameter, handle it immediately
        String matchingMethodParamName = ModelUtils.getParameterName(context, matchingMethodParameters.get(0));
        // Find the matching operation parameter
        for (Parameter operationParam : context.getWorkingOperation().getParameters()) {
            if (operationParam.getName().equals(matchingMethodParamName)) {
                return operationParam;
            }
        }
    }
    return null;
}
Also used : RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl) Components(org.eclipse.microprofile.openapi.models.Components) Arrays(java.util.Arrays) ExtensibleImpl(fish.payara.microprofile.openapi.impl.model.ExtensibleImpl) ModelUtils.isVoid(fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isVoid) PathItem(org.eclipse.microprofile.openapi.models.PathItem) ExtensibleType(org.glassfish.hk2.classmodel.reflect.ExtensibleType) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) ParameterizedType(org.glassfish.hk2.classmodel.reflect.ParameterizedType) DefaultValue(javax.ws.rs.DefaultValue) MediaTypeImpl(fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl) Method(java.lang.reflect.Method) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) Collection(java.util.Collection) AnnotatedElement(org.glassfish.hk2.classmodel.reflect.AnnotatedElement) Set(java.util.Set) WARNING(java.util.logging.Level.WARNING) OpenAPIImpl(fish.payara.microprofile.openapi.impl.model.OpenAPIImpl) ApiVisitor(fish.payara.microprofile.openapi.api.visitor.ApiVisitor) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) List(java.util.List) ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl) TagImpl(fish.payara.microprofile.openapi.impl.model.tags.TagImpl) SchemaType(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl) ExternalDocumentation(org.eclipse.microprofile.openapi.models.ExternalDocumentation) Entry(java.util.Map.Entry) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Server(org.eclipse.microprofile.openapi.models.servers.Server) OASProcessor(fish.payara.microprofile.openapi.api.processor.OASProcessor) OpenApiConfiguration(fish.payara.microprofile.openapi.impl.config.OpenApiConfiguration) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) SecuritySchemeImpl(fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement) APIResponse(org.eclipse.microprofile.openapi.models.responses.APIResponse) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel) ModelUtils(fish.payara.microprofile.openapi.impl.model.util.ModelUtils) HttpMethod(javax.ws.rs.HttpMethod) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) SEVERE(java.util.logging.Level.SEVERE) SecurityRequirementImpl(fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl) Operation(org.eclipse.microprofile.openapi.models.Operation) ParameterizedInterfaceModel(org.glassfish.hk2.classmodel.reflect.ParameterizedInterfaceModel) Schema(org.eclipse.microprofile.openapi.models.media.Schema) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) Status(javax.ws.rs.core.Response.Status) FINE(java.util.logging.Level.FINE) Callback(org.eclipse.microprofile.openapi.models.callbacks.Callback) Types(org.glassfish.hk2.classmodel.reflect.Types) FormParam(javax.ws.rs.FormParam) OpenApiWalker(fish.payara.microprofile.openapi.impl.visitor.OpenApiWalker) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) CallbackImpl(fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl) APIResponsesImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponsesImpl) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) EnumType(org.glassfish.hk2.classmodel.reflect.EnumType) ParameterImpl(fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) ExternalDocumentationImpl(fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl) Reference(org.eclipse.microprofile.openapi.models.Reference) ApiContext(fish.payara.microprofile.openapi.api.visitor.ApiContext) Collections(java.util.Collections) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) ClassModel(org.glassfish.hk2.classmodel.reflect.ClassModel) In(org.eclipse.microprofile.openapi.models.parameters.Parameter.In) Type(org.glassfish.hk2.classmodel.reflect.Type) In(org.eclipse.microprofile.openapi.models.parameters.Parameter.In) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter)

Example 10 with Parameter

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

the class ApplicationProcessor method visitSchemaParameter.

private static void visitSchemaParameter(AnnotationModel schemaAnnotation, org.glassfish.hk2.classmodel.reflect.Parameter parameter, ApiContext context) {
    // If this is being parsed at the start, ignore it as the path doesn't exist
    if (context.getWorkingOperation() == null) {
        return;
    }
    // Check if it's a request body
    if (ModelUtils.isRequestBody(context, parameter)) {
        if (context.getWorkingOperation().getRequestBody() == null) {
            context.getWorkingOperation().setRequestBody(new RequestBodyImpl());
        }
        // Insert the schema to the request body media type
        MediaType mediaType = context.getWorkingOperation().getRequestBody().getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD);
        Schema schema = SchemaImpl.createInstance(schemaAnnotation, context);
        SchemaImpl.merge(schema, mediaType.getSchema(), true, context);
        if (schema.getRef() != null && !schema.getRef().isEmpty()) {
            mediaType.setSchema(new SchemaImpl().ref(schema.getRef()));
        }
    } else if (ModelUtils.getParameterType(context, parameter) != null) {
        for (Parameter param : context.getWorkingOperation().getParameters()) {
            if (param.getName().equals(ModelUtils.getParameterName(context, parameter))) {
                Schema schema = SchemaImpl.createInstance(schemaAnnotation, context);
                SchemaImpl.merge(schema, param.getSchema(), true, context);
                if (schema.getRef() != null && !schema.getRef().isEmpty()) {
                    param.setSchema(new SchemaImpl().ref(schema.getRef()));
                }
            }
        }
    }
}
Also used : SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Schema(org.eclipse.microprofile.openapi.models.media.Schema) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)

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