use of io.swagger.v3.oas.annotations.Operation 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.swagger.v3.oas.annotations.Operation 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.swagger.v3.oas.annotations.Operation 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.swagger.v3.oas.annotations.Operation 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));
}
use of io.swagger.v3.oas.annotations.Operation in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testQueryParameterNotRequired.
@Test
public void testQueryParameterNotRequired() throws Exception {
Operation op = testSpec.getPaths().get("/pets").getGet();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
loadHandlers("/pets", HttpMethod.GET, false, validationHandler, (routingContext) -> {
routingContext.response().setStatusMessage("ok").end();
});
testRequest(HttpMethod.GET, "/pets", 200, "ok");
}
Aggregations