Search in sources :

Example 56 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 57 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 58 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 59 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)

Example 60 with Operation

use of io.swagger.v3.oas.models.Operation 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)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)177 Operation (io.swagger.v3.oas.models.Operation)174 OpenAPI (io.swagger.v3.oas.models.OpenAPI)141 Test (org.testng.annotations.Test)129 PathItem (io.swagger.v3.oas.models.PathItem)108 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 Schema (io.swagger.v3.oas.models.media.Schema)68 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)62 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)59 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)55 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)51 ArrayList (java.util.ArrayList)51 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)50 StringSchema (io.swagger.v3.oas.models.media.StringSchema)48 MediaType (io.swagger.v3.oas.models.media.MediaType)44 Path (javax.ws.rs.Path)44 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)43 Content (io.swagger.v3.oas.models.media.Content)42 lombok.val (lombok.val)42 Parameter (io.swagger.v3.oas.models.parameters.Parameter)39