Search in sources :

Example 16 with Operation

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");
}
Also used : MultiMap(io.vertx.core.MultiMap) 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 17 with Operation

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");
}
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 18 with Operation

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);
}
Also used : OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) JsonObject(io.vertx.core.json.JsonObject) Operation(io.swagger.v3.oas.models.Operation) RequestParameters(io.vertx.ext.web.api.RequestParameters) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with Operation

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");
}
Also used : ValidationException(io.vertx.ext.web.api.validation.ValidationException) RequestParameter(io.vertx.ext.web.api.RequestParameter) MultiMap(io.vertx.core.MultiMap) Test(org.junit.Test) Operation(io.swagger.v3.oas.models.Operation) OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) ParameterType(io.vertx.ext.web.api.validation.ParameterType) WebTestValidationBase(io.vertx.ext.web.api.validation.WebTestValidationBase) ArrayList(java.util.ArrayList) List(java.util.List) Rule(org.junit.Rule) ExternalResource(org.junit.rules.ExternalResource) Ignore(org.junit.Ignore) OpenAPI(io.swagger.v3.oas.models.OpenAPI) HttpMethod(io.vertx.core.http.HttpMethod) RequestParameters(io.vertx.ext.web.api.RequestParameters) JsonObject(io.vertx.core.json.JsonObject) OpenApi3Utils(io.vertx.ext.web.api.contract.openapi3.impl.OpenApi3Utils) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) Operation(io.swagger.v3.oas.models.Operation) Test(org.junit.Test)

Example 20 with Operation

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");
}
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)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)151 Operation (io.swagger.v3.oas.models.Operation)108 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 OpenAPI (io.swagger.v3.oas.models.OpenAPI)79 Test (org.testng.annotations.Test)68 PathItem (io.swagger.v3.oas.models.PathItem)53 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)50 ArrayList (java.util.ArrayList)45 lombok.val (lombok.val)42 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)34 Map (java.util.Map)34 HashMap (java.util.HashMap)33 LinkedHashMap (java.util.LinkedHashMap)29 Test (org.junit.Test)29 OpenAPI3RequestValidationHandlerImpl (io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl)28 Paths (io.swagger.v3.oas.models.Paths)27 Components (io.swagger.v3.oas.models.Components)26 Schema (io.swagger.v3.oas.models.media.Schema)24 Produces (javax.ws.rs.Produces)21 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)20