use of io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl 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));
}
use of io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testEmptyBody.
@Test
public void testEmptyBody() throws Exception {
Operation op = testSpec.getPaths().get("/multipart/complex").getPost();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
loadHandlers("/multipart/complex", HttpMethod.POST, false, validationHandler, (routingContext) -> {
routingContext.response().setStatusMessage("ok").end();
});
testRequest(HttpMethod.POST, "/multipart/complex", 200, "ok");
}
use of io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl 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));
}
use of io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl 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));
}
use of io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testNullJson.
@Test
public void testNullJson() throws Exception {
Operation op = testSpec.getPaths().get("/pets").getPost();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
loadHandlers("/pets", 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());
});
// An empty body should be a non parsable json, not an empty object invalid
testRequestWithJSON(HttpMethod.POST, "/pets", null, 400, errorMessage(ValidationException.ErrorType.JSON_INVALID));
// An empty json object should be invalid, because some fields are required
testRequestWithJSON(HttpMethod.POST, "/pets", new JsonObject(), 400, errorMessage(ValidationException.ErrorType.JSON_INVALID));
}
Aggregations