Search in sources :

Example 16 with OpenAPI3RequestValidationHandlerImpl

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

the class OpenAPI3ValidationTest method testPathParameter.

@Test
public void testPathParameter() throws Exception {
    Operation op = testSpec.getPaths().get("/pets/{petId}").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/pets/:petId", HttpMethod.GET, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        routingContext.response().setStatusMessage(params.pathParameter("petId").getInteger().toString()).end();
    });
    testRequest(HttpMethod.GET, "/pets/3", 200, "3");
}
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 17 with OpenAPI3RequestValidationHandlerImpl

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

the class OpenAPI3ValidationTest method testPathParameterFailure.

@Test
public void testPathParameterFailure() throws Exception {
    Operation op = testSpec.getPaths().get("/pets/{petId}").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/pets/:petId", HttpMethod.GET, true, validationHandler, (routingContext) -> {
        routingContext.response().setStatusMessage("ok").end();
    });
    testRequest(HttpMethod.GET, "/pets/three", 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 18 with OpenAPI3RequestValidationHandlerImpl

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

the class OpenAPI3ValidationTest method testDefaultIntQueryParameter.

@Test
public void testDefaultIntQueryParameter() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/defaultInt").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/defaultInt", HttpMethod.GET, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        RequestParameter requestParameter = params.queryParameter("parameter");
        assertTrue(requestParameter.isInteger());
        routingContext.response().setStatusMessage(requestParameter.toString()).end();
    });
    testRequest(HttpMethod.GET, "/queryTests/defaultInt", 200, "1");
}
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)

Example 19 with OpenAPI3RequestValidationHandlerImpl

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

the class OpenAPI3ValidationTest method testDefaultStringQueryParameter.

@Test
public void testDefaultStringQueryParameter() 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();
    });
    testRequest(HttpMethod.GET, "/queryTests/defaultString", 200, "aString");
}
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 20 with OpenAPI3RequestValidationHandlerImpl

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

the class OpenAPI3ValidationTest method testFormArrayParameter.

@Test
public void testFormArrayParameter() 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, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        List<String> result = new ArrayList<>();
        for (RequestParameter r : params.formParameter("values").getArray()) result.add(r.getInteger().toString());
        routingContext.response().setStatusMessage(params.formParameter("id").getString() + serializeInCSVStringArray(result)).end();
    });
    String id = "anId";
    List<String> valuesArray = new ArrayList<>();
    for (int i = 0; i < 4; i++) valuesArray.add(getSuccessSample(ParameterType.INT).getInteger().toString());
    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, 200, id + values);
}
Also used : MultiMap(io.vertx.core.MultiMap) 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)

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