Search in sources :

Example 56 with Parameter

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

the class OpenAPI3ValidationTest method testQueryParameterArrayDefaultStyle.

@Test
public void testQueryParameterArrayDefaultStyle() 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, 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");
    testRequest(HttpMethod.GET, "/queryTests/arrayTests/default?parameter=" + serializeInCSVStringArray(values), 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 57 with Parameter

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

the class OpenAPI3ValidationTest method testAllOfQueryParamFailure.

@Test
public void testAllOfQueryParamFailure() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/allOfTest").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/allOfTest", HttpMethod.GET, true, validationHandler, (routingContext) -> {
        routingContext.response().setStatusMessage("ok").end();
    });
    String a = "5";
    String b = "aString";
    String parameter = "parameter=a," + a + ",b," + b;
    testRequest(HttpMethod.GET, "/queryTests/allOfTest?" + parameter, 400, errorMessage(ValidationException.ErrorType.NO_MATCH));
}
Also used : OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) Operation(io.swagger.v3.oas.models.Operation) Test(org.junit.Test)

Example 58 with Parameter

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

the class OpenAPI3ValidationTest method testQueryParameterAnyOfFailure.

@Test
public void testQueryParameterAnyOfFailure() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/anyOfTest").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/anyOfTest", HttpMethod.GET, true, validationHandler, (routingContext) -> {
        routingContext.response().setStatusMessage("ok").end();
    });
    testRequest(HttpMethod.GET, "/queryTests/anyOfTest?parameter=anyString", 400, errorMessage(ValidationException.ErrorType.NO_MATCH));
}
Also used : OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) Operation(io.swagger.v3.oas.models.Operation) Test(org.junit.Test)

Example 59 with Parameter

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

the class OpenAPI3ValidationTest method testAllOfQueryParamWithDefault.

@Test
public void testAllOfQueryParamWithDefault() 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 = "";
    String parameter = "parameter=a," + a + ",b," + b;
    testRequest(HttpMethod.GET, "/queryTests/allOfTest?" + parameter, 200, a + "false");
}
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 60 with Parameter

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

the class OpenAPI3ValidationTest method testQueryParameterByteFormat.

@Test
public void testQueryParameterByteFormat() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/byteFormat").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/byteFormat", HttpMethod.GET, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        routingContext.response().setStatusMessage(params.queryParameter("parameter").getString()).end();
    });
    testRequest(HttpMethod.GET, "/queryTests/byteFormat?parameter=Zm9vYmFyCg==", 200, "Zm9vYmFyCg==");
}
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)

Aggregations

Parameter (io.swagger.v3.oas.models.parameters.Parameter)48 Test (org.testng.annotations.Test)39 Operation (io.swagger.v3.oas.models.Operation)28 Operation (io.swagger.v3.oas.annotations.Operation)27 lombok.val (lombok.val)26 OpenAPI (io.swagger.v3.oas.models.OpenAPI)20 Map (java.util.Map)17 ArrayList (java.util.ArrayList)16 ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)15 OpenAPI3RequestValidationHandlerImpl (io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl)14 Test (org.junit.Test)14 PathItem (io.swagger.v3.oas.models.PathItem)13 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)13 StringUtils (org.apache.commons.lang3.StringUtils)13 StringSchema (io.swagger.v3.oas.models.media.StringSchema)12 LinkedHashMap (java.util.LinkedHashMap)12 Parameter (io.swagger.v3.oas.annotations.Parameter)11 RequestParameters (io.vertx.ext.web.api.RequestParameters)11 HashMap (java.util.HashMap)11 Schema (io.swagger.v3.oas.models.media.Schema)10