use of io.swagger.v3.oas.models.Operation in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testComplexMultipart.
@Test
public void testComplexMultipart() 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) -> {
RequestParameters params = routingContext.get("parsedParameters");
assertEquals(params.formParameter("param1").getString(), "sampleString");
assertNotNull(params.formParameter("param2").getJsonObject());
assertEquals(params.formParameter("param2").getJsonObject().getString("name"), "Willy");
assertEquals(params.formParameter("param4").getArray().size(), 4);
routingContext.response().setStatusMessage("ok").end();
});
MultiMap form = MultiMap.caseInsensitiveMultiMap();
form.add("param1", "sampleString");
JsonObject pet = new JsonObject();
pet.put("id", 14612);
pet.put("name", "Willy");
form.add("param2", pet.encode());
form.add("param3", "SELECT * FROM table;");
List<String> valuesArray = new ArrayList<>();
for (int i = 0; i < 4; i++) valuesArray.add(getSuccessSample(ParameterType.FLOAT).getFloat().toString());
form.add("param4", serializeInCSVStringArray(valuesArray));
testRequestWithForm(HttpMethod.POST, "/multipart/complex", FormType.MULTIPART, form, 200, "ok");
}
use of io.swagger.v3.oas.models.Operation in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testDefaultDoubleQueryParameter.
@Test
public void testDefaultDoubleQueryParameter() throws Exception {
Operation op = testSpec.getPaths().get("/queryTests/defaultDouble").getGet();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
loadHandlers("/queryTests/defaultDouble", HttpMethod.GET, false, validationHandler, (routingContext) -> {
RequestParameters params = routingContext.get("parsedParameters");
RequestParameter requestParameter = params.queryParameter("parameter");
assertTrue(requestParameter.isDouble());
routingContext.response().setStatusMessage(requestParameter.toString()).end();
});
testRequest(HttpMethod.GET, "/queryTests/defaultDouble", 200, "1.0");
}
use of io.swagger.v3.oas.models.Operation in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testCircularReferences.
@Test
@Ignore
public void testCircularReferences() throws Exception {
Operation op = testSpec.getPaths().get("/circularReferences").getPost();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
loadHandlers("/circularReferences", HttpMethod.POST, false, validationHandler, (routingContext) -> {
RequestParameters params = routingContext.get("parsedParameters");
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("Content-Type", "application/json").end(params.body().getJsonObject().encode());
});
JsonObject obj = new JsonObject("{\n" + " \"a\": {\n" + " \"a\": [\n" + " {\n" + " \"a\": {\n" + " \"a\": []\n" + " },\n" + " \"b\": \"hi\",\n" + " \"c\": 10\n" + " }\n" + " ]\n" + " },\n" + " \"b\": \"hello\",\n" + " \"c\": 6\n" + "}");
testRequestWithJSON(HttpMethod.POST, "/circularReferences", obj, 200, "OK", obj);
}
use of io.swagger.v3.oas.models.Operation in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testLoadSampleOperationObject.
@Test
public void testLoadSampleOperationObject() throws Exception {
Operation op = testSpec.getPaths().get("/pets").getGet();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
router.get("/pets").handler(validationHandler);
router.get("/pets").handler(routingContext -> {
routingContext.response().setStatusMessage("ok").end();
}).failureHandler(generateFailureHandler(false));
testRequest(HttpMethod.GET, "/pets", 200, "ok");
}
use of io.swagger.v3.oas.models.Operation 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");
}
Aggregations