Search in sources :

Example 1 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project syncope by apache.

the class SyncopeOpenApiCustomizer method addParameters.

@Override
protected void addParameters(final List<Parameter> parameters) {
    if (domains == null) {
        domains = new ArrayList<>(ApplicationContextProvider.getApplicationContext().getBean(DomainsHolder.class).getDomains().keySet());
    }
    Optional<Parameter> domainHeaderParameter = parameters.stream().filter(parameter -> parameter instanceof HeaderParameter && RESTHeaders.DOMAIN.equals(parameter.getName())).findFirst();
    if (!domainHeaderParameter.isPresent()) {
        HeaderParameter parameter = new HeaderParameter();
        parameter.setName(RESTHeaders.DOMAIN);
        parameter.setRequired(true);
        Schema<String> schema = new Schema<>();
        schema.setType("string");
        schema.setEnum(domains);
        schema.setDefault(SyncopeConstants.MASTER_DOMAIN);
        parameter.setSchema(schema);
        parameters.add(parameter);
    }
}
Also used : ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) Content(io.swagger.v3.oas.models.media.Content) URL(java.net.URL) MediaType(io.swagger.v3.oas.models.media.MediaType) Parameter(io.swagger.v3.oas.models.parameters.Parameter) OpenAPIConfiguration(io.swagger.v3.oas.integration.api.OpenAPIConfiguration) Header(io.swagger.v3.oas.models.headers.Header) ErrorTO(org.apache.syncope.common.lib.to.ErrorTO) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) DomainsHolder(org.apache.syncope.core.persistence.api.DomainsHolder) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) Map(java.util.Map) OpenApiCustomizer(org.apache.cxf.jaxrs.openapi.OpenApiCustomizer) Optional(java.util.Optional) Schema(io.swagger.v3.oas.models.media.Schema) RESTHeaders(org.apache.syncope.common.rest.api.RESTHeaders) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) Schema(io.swagger.v3.oas.models.media.Schema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter)

Example 2 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project vertx-web by vert-x3.

the class OpenAPI3ValidationTest method testQueryParameterArrayExploded.

@Test
public void testQueryParameterArrayExploded() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/arrayTests/formExploded").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/arrayTests/formExploded", HttpMethod.GET, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        List<String> result = new ArrayList<>();
        for (RequestParameter r : params.queryParameter("parameter").getArray()) result.add(r.getInteger().toString());
        routingContext.response().setStatusMessage(serializeInCSVStringArray(result)).end();
    });
    List<String> values = new ArrayList<>();
    values.add("4");
    values.add("2");
    values.add("26");
    StringBuilder stringBuilder = new StringBuilder();
    for (String s : values) {
        stringBuilder.append("parameter=" + s + "&");
    }
    stringBuilder.deleteCharAt(stringBuilder.length() - 1);
    testRequest(HttpMethod.GET, "/queryTests/arrayTests/formExploded?" + stringBuilder, 200, serializeInCSVStringArray(values));
}
Also used : OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) RequestParameter(io.vertx.ext.web.api.RequestParameter) ArrayList(java.util.ArrayList) Operation(io.swagger.v3.oas.models.Operation) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Example 3 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project vertx-web by vert-x3.

the class OpenAPI3ValidationTest method testAllowEmptyValueQueryParameter.

@Test
public void testAllowEmptyValueQueryParameter() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/defaultString").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/defaultString", HttpMethod.GET, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        routingContext.response().setStatusMessage(params.queryParameter("parameter").getString()).end();
    });
    // Empty value should not be overwritten
    testRequest(HttpMethod.GET, "/queryTests/defaultString?parameter=", 200, "");
}
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 4 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project vertx-web by vert-x3.

the class OpenAPI3ValidationTest method testAllOfQueryParam.

@Test
public void testAllOfQueryParam() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/allOfTest").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/allOfTest", HttpMethod.GET, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        routingContext.response().setStatusMessage(params.queryParameter("parameter").getObjectValue("a").getInteger().toString() + params.queryParameter("parameter").getObjectValue("b").getBoolean().toString()).end();
    });
    String a = "5";
    String b = "false";
    String parameter = "parameter=a," + a + ",b," + b;
    testRequest(HttpMethod.GET, "/queryTests/allOfTest?" + parameter, 200, a + b);
}
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 5 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project vertx-web by vert-x3.

the class OpenAPI3ValidationTest method testQueryParameterArrayDefaultStyleFailure.

@Test
public void testQueryParameterArrayDefaultStyleFailure() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/arrayTests/default").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/arrayTests/default", HttpMethod.GET, true, validationHandler, (routingContext) -> {
        routingContext.response().setStatusMessage("ok").end();
    });
    List<String> values = new ArrayList<>();
    values.add("4");
    // multipleOf: 2
    values.add("1");
    values.add("26");
    testRequest(HttpMethod.GET, "/queryTests/arrayTests/default?parameter=" + serializeInCSVStringArray(values), 400, errorMessage(ValidationException.ErrorType.NO_MATCH));
}
Also used : OpenAPI3RequestValidationHandlerImpl(io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl) ArrayList(java.util.ArrayList) Operation(io.swagger.v3.oas.models.Operation) Test(org.junit.Test)

Aggregations

Parameter (io.swagger.v3.oas.models.parameters.Parameter)110 Test (org.testng.annotations.Test)83 Operation (io.swagger.v3.oas.annotations.Operation)66 OpenAPI (io.swagger.v3.oas.models.OpenAPI)63 Operation (io.swagger.v3.oas.models.Operation)47 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)46 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)40 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)38 Schema (io.swagger.v3.oas.models.media.Schema)36 PathItem (io.swagger.v3.oas.models.PathItem)30 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)30 HeaderParameter (io.swagger.v3.oas.models.parameters.HeaderParameter)30 StringSchema (io.swagger.v3.oas.models.media.StringSchema)28 ArrayList (java.util.ArrayList)27 lombok.val (lombok.val)26 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)25 Map (java.util.Map)24 Components (io.swagger.v3.oas.models.Components)22 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)22 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)20