Search in sources :

Example 31 with Operation

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

Example 32 with Operation

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

Example 33 with Operation

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

Example 34 with Operation

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));
}
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) Test(org.junit.Test)

Example 35 with Operation

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");
}
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.models.Operation)31 OpenAPI3RequestValidationHandlerImpl (io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl)28 Test (org.junit.Test)28 RequestParameters (io.vertx.ext.web.api.RequestParameters)21 ArrayList (java.util.ArrayList)12 JsonObject (io.vertx.core.json.JsonObject)7 RequestParameter (io.vertx.ext.web.api.RequestParameter)7 Operation (io.swagger.v3.oas.annotations.Operation)6 MultiMap (io.vertx.core.MultiMap)5 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)3 Produces (javax.ws.rs.Produces)3 Charsets (com.google.common.base.Charsets)2 OpenAPIConfiguration (io.swagger.v3.oas.integration.api.OpenAPIConfiguration)2 OpenAPI (io.swagger.v3.oas.models.OpenAPI)2 HttpMethod (io.swagger.v3.oas.models.PathItem.HttpMethod)2 Parameter (io.swagger.v3.oas.models.parameters.Parameter)2 Tag (io.swagger.v3.oas.models.tags.Tag)2 List (java.util.List)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2