Search in sources :

Example 6 with OpenAPI3RequestValidationHandlerImpl

use of io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl 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)

Example 7 with OpenAPI3RequestValidationHandlerImpl

use of io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl in project vertx-web by vert-x3.

the class OpenAPI3ValidationTest method testJsonBodyFailure.

@Test
public void testJsonBodyFailure() throws Exception {
    Operation op = testSpec.getPaths().get("/jsonBodyTest/sampleTest").getPost();
    if (op.getParameters() == null)
        op.setParameters(new ArrayList<>());
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/jsonBodyTest/sampleTest", HttpMethod.POST, true, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("Content-Type", "application/json").end(params.body().getJsonObject().encode());
    });
    JsonObject object = new JsonObject();
    object.put("id", "anId");
    List<String> valuesArray = new ArrayList<>();
    for (int i = 0; i < 4; i++) valuesArray.add(getSuccessSample(ParameterType.INT).getInteger().toString());
    valuesArray.add(2, getFailureSample(ParameterType.INT));
    object.put("values", valuesArray);
    testRequestWithJSON(HttpMethod.POST, "/jsonBodyTest/sampleTest", object, 400, errorMessage(ValidationException.ErrorType.JSON_INVALID), null);
}
Also used : OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Operation(io.swagger.v3.oas.models.Operation) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Example 8 with OpenAPI3RequestValidationHandlerImpl

use of io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl in project vertx-web by vert-x3.

the class OpenAPI3ValidationTest method testFormArrayParameterFailure.

@Test
public void testFormArrayParameterFailure() throws Exception {
    Operation op = testSpec.getPaths().get("/formTests/arraytest").getPost();
    if (op.getParameters() == null)
        op.setParameters(new ArrayList<>());
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/formTests/arraytest", HttpMethod.POST, true, validationHandler, (routingContext) -> {
        routingContext.response().setStatusMessage("ok").end();
    });
    String id = "anId";
    List<String> valuesArray = new ArrayList<>();
    for (int i = 0; i < 4; i++) valuesArray.add(getSuccessSample(ParameterType.INT).getInteger().toString());
    valuesArray.add(getFailureSample(ParameterType.INT));
    String values = serializeInCSVStringArray(valuesArray);
    MultiMap form = MultiMap.caseInsensitiveMultiMap();
    form.add("id", id);
    form.add("values", values);
    testRequestWithForm(HttpMethod.POST, "/formTests/arraytest", FormType.FORM_URLENCODED, form, 400, errorMessage(ValidationException.ErrorType.NO_MATCH));
}
Also used : MultiMap(io.vertx.core.MultiMap) 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)

Example 9 with OpenAPI3RequestValidationHandlerImpl

use of io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl in project vertx-web by vert-x3.

the class OpenAPI3ValidationTest method testFormURLEncodedCharParameter.

@Test
public void testFormURLEncodedCharParameter() throws Exception {
    Operation op = testSpec.getPaths().get("/formTests/urlencodedchar").getPost();
    if (op.getParameters() == null)
        op.setParameters(new ArrayList<>());
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/formTests/urlencodedchar", HttpMethod.POST, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        routingContext.response().setStatusMessage(params.formParameter("name").getString()).end();
    });
    String name = "test+urlencoded+char";
    MultiMap form = MultiMap.caseInsensitiveMultiMap();
    form.add("name", name);
    testRequestWithForm(HttpMethod.POST, "/formTests/urlencodedchar", FormType.FORM_URLENCODED, form, 200, name);
}
Also used : MultiMap(io.vertx.core.MultiMap) OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) ArrayList(java.util.ArrayList) Operation(io.swagger.v3.oas.models.Operation) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Example 10 with OpenAPI3RequestValidationHandlerImpl

use of io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl in project vertx-web by vert-x3.

the class OpenAPI3ValidationTest method testDefaultFloatQueryParameter.

@Test
public void testDefaultFloatQueryParameter() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/defaultFloat").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/defaultFloat", HttpMethod.GET, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        RequestParameter requestParameter = params.queryParameter("parameter");
        assertTrue(requestParameter.isFloat());
        routingContext.response().setStatusMessage(requestParameter.toString()).end();
    });
    testRequest(HttpMethod.GET, "/queryTests/defaultFloat", 200, "1.0");
}
Also used : OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) RequestParameter(io.vertx.ext.web.api.RequestParameter) Operation(io.swagger.v3.oas.models.Operation) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Aggregations

Operation (io.swagger.v3.oas.models.Operation)28 OpenAPI3RequestValidationHandlerImpl (io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl)28 Test (org.junit.Test)28 RequestParameters (io.vertx.ext.web.api.RequestParameters)21 ArrayList (java.util.ArrayList)10 JsonObject (io.vertx.core.json.JsonObject)7 RequestParameter (io.vertx.ext.web.api.RequestParameter)7 MultiMap (io.vertx.core.MultiMap)5 Ignore (org.junit.Ignore)2 OpenAPI (io.swagger.v3.oas.models.OpenAPI)1 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)1 HttpMethod (io.vertx.core.http.HttpMethod)1 OpenApi3Utils (io.vertx.ext.web.api.contract.openapi3.impl.OpenApi3Utils)1 ParameterType (io.vertx.ext.web.api.validation.ParameterType)1 ValidationException (io.vertx.ext.web.api.validation.ValidationException)1 WebTestValidationBase (io.vertx.ext.web.api.validation.WebTestValidationBase)1 List (java.util.List)1 Rule (org.junit.Rule)1 ExternalResource (org.junit.rules.ExternalResource)1