Search in sources :

Example 1 with Parameter

use of io.swagger.v3.oas.annotations.Parameter in project cxf by apache.

the class JaxRs2Extension method extractParameters.

@Override
public ResolvedParameter extractParameters(final List<Annotation> annotations, final Type type, final Set<Type> typesToSkip, final Components components, final Consumes classConsumes, final Consumes methodConsumes, final boolean includeRequestBody, final JsonView jsonViewAnnotation, final Iterator<OpenAPIExtension> chain) {
    if (shouldIgnoreType(type, typesToSkip)) {
        return new ResolvedParameter();
    }
    List<Parameter> parameters = annotations.stream().filter(annotation -> annotation instanceof MatrixParam).map(annotation -> {
        MatrixParam param = (MatrixParam) annotation;
        Parameter mp = new PathParameter().name(param.value());
        mp.setStyle(Parameter.StyleEnum.MATRIX);
        ResolvedSchema resolvedSchema = ModelConverters.getInstance().readAllAsResolvedSchema(type);
        if (resolvedSchema != null) {
            mp.setSchema(resolvedSchema.schema);
        }
        applyBeanValidatorAnnotations(mp, annotations);
        return mp;
    }).collect(Collectors.toList());
    // Only call down to the other items in the chain if no parameters were produced
    if (parameters.isEmpty()) {
        return super.extractParameters(annotations, type, typesToSkip, components, classConsumes, methodConsumes, includeRequestBody, jsonViewAnnotation, chain);
    }
    ResolvedParameter resolved = new ResolvedParameter();
    resolved.parameters = parameters;
    return resolved;
}
Also used : Size(javax.validation.constraints.Size) AbstractOpenAPIExtension(io.swagger.v3.jaxrs2.ext.AbstractOpenAPIExtension) JsonView(com.fasterxml.jackson.annotation.JsonView) ResolvedSchema(io.swagger.v3.core.converter.ResolvedSchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) DecimalMin(javax.validation.constraints.DecimalMin) HashMap(java.util.HashMap) ResolvedParameter(io.swagger.v3.jaxrs2.ResolvedParameter) BigDecimal(java.math.BigDecimal) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) Max(javax.validation.constraints.Max) Schema(io.swagger.v3.oas.models.media.Schema) Iterator(java.util.Iterator) Set(java.util.Set) Min(javax.validation.constraints.Min) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) OpenAPIExtension(io.swagger.v3.jaxrs2.ext.OpenAPIExtension) ModelConverters(io.swagger.v3.core.converter.ModelConverters) List(java.util.List) Type(java.lang.reflect.Type) DecimalMax(javax.validation.constraints.DecimalMax) Annotation(java.lang.annotation.Annotation) Pattern(javax.validation.constraints.Pattern) MatrixParam(javax.ws.rs.MatrixParam) Components(io.swagger.v3.oas.models.Components) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) MatrixParam(javax.ws.rs.MatrixParam) ResolvedParameter(io.swagger.v3.jaxrs2.ResolvedParameter) Parameter(io.swagger.v3.oas.models.parameters.Parameter) ResolvedParameter(io.swagger.v3.jaxrs2.ResolvedParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) ResolvedSchema(io.swagger.v3.core.converter.ResolvedSchema) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter)

Example 2 with Parameter

use of io.swagger.v3.oas.annotations.Parameter in project vertx-web by vert-x3.

the class OpenAPI3ValidationTest method testQueryParameterArrayExploded.

@Test
public void testQueryParameterArrayExploded() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/arrayTests/formExploded").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/arrayTests/formExploded", HttpMethod.GET, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        List<String> result = new ArrayList<>();
        for (RequestParameter r : params.queryParameter("parameter").getArray()) result.add(r.getInteger().toString());
        routingContext.response().setStatusMessage(serializeInCSVStringArray(result)).end();
    });
    List<String> values = new ArrayList<>();
    values.add("4");
    values.add("2");
    values.add("26");
    StringBuilder stringBuilder = new StringBuilder();
    for (String s : values) {
        stringBuilder.append("parameter=" + s + "&");
    }
    stringBuilder.deleteCharAt(stringBuilder.length() - 1);
    testRequest(HttpMethod.GET, "/queryTests/arrayTests/formExploded?" + stringBuilder, 200, serializeInCSVStringArray(values));
}
Also used : OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) RequestParameter(io.vertx.ext.web.api.RequestParameter) ArrayList(java.util.ArrayList) Operation(io.swagger.v3.oas.models.Operation) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Example 3 with Parameter

use of io.swagger.v3.oas.annotations.Parameter in project vertx-web by vert-x3.

the class OpenAPI3ValidationTest method testAllowEmptyValueQueryParameter.

@Test
public void testAllowEmptyValueQueryParameter() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/defaultString").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/defaultString", HttpMethod.GET, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        routingContext.response().setStatusMessage(params.queryParameter("parameter").getString()).end();
    });
    // Empty value should not be overwritten
    testRequest(HttpMethod.GET, "/queryTests/defaultString?parameter=", 200, "");
}
Also used : OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) Operation(io.swagger.v3.oas.models.Operation) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Example 4 with Parameter

use of io.swagger.v3.oas.annotations.Parameter in project vertx-web by vert-x3.

the class OpenAPI3ValidationTest method testAllOfQueryParam.

@Test
public void testAllOfQueryParam() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/allOfTest").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/allOfTest", HttpMethod.GET, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        routingContext.response().setStatusMessage(params.queryParameter("parameter").getObjectValue("a").getInteger().toString() + params.queryParameter("parameter").getObjectValue("b").getBoolean().toString()).end();
    });
    String a = "5";
    String b = "false";
    String parameter = "parameter=a," + a + ",b," + b;
    testRequest(HttpMethod.GET, "/queryTests/allOfTest?" + parameter, 200, a + b);
}
Also used : OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) Operation(io.swagger.v3.oas.models.Operation) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Example 5 with Parameter

use of io.swagger.v3.oas.annotations.Parameter in project vertx-web by vert-x3.

the class OpenAPI3ValidationTest method testQueryParameterArrayDefaultStyleFailure.

@Test
public void testQueryParameterArrayDefaultStyleFailure() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/arrayTests/default").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/arrayTests/default", HttpMethod.GET, true, validationHandler, (routingContext) -> {
        routingContext.response().setStatusMessage("ok").end();
    });
    List<String> values = new ArrayList<>();
    values.add("4");
    // multipleOf: 2
    values.add("1");
    values.add("26");
    testRequest(HttpMethod.GET, "/queryTests/arrayTests/default?parameter=" + serializeInCSVStringArray(values), 400, errorMessage(ValidationException.ErrorType.NO_MATCH));
}
Also used : OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) ArrayList(java.util.ArrayList) Operation(io.swagger.v3.oas.models.Operation) Test(org.junit.Test)

Aggregations

Operation (io.swagger.v3.oas.models.Operation)15 OpenAPI3RequestValidationHandlerImpl (io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl)14 Test (org.junit.Test)14 RequestParameters (io.vertx.ext.web.api.RequestParameters)11 Parameter (io.swagger.v3.oas.models.parameters.Parameter)5 RequestParameter (io.vertx.ext.web.api.RequestParameter)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Schema (io.swagger.v3.oas.models.media.Schema)2 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 JsonView (com.fasterxml.jackson.annotation.JsonView)1 ModelConverters (io.swagger.v3.core.converter.ModelConverters)1 ResolvedSchema (io.swagger.v3.core.converter.ResolvedSchema)1 ResolvedParameter (io.swagger.v3.jaxrs2.ResolvedParameter)1 AbstractOpenAPIExtension (io.swagger.v3.jaxrs2.ext.AbstractOpenAPIExtension)1 OpenAPIExtension (io.swagger.v3.jaxrs2.ext.OpenAPIExtension)1