Search in sources :

Example 61 with Operation

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

the class OpenAPI3ValidationTest method testDefaultIntQueryParameter.

@Test
public void testDefaultIntQueryParameter() throws Exception {
    Operation op = testSpec.getPaths().get("/queryTests/defaultInt").getGet();
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/queryTests/defaultInt", HttpMethod.GET, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        RequestParameter requestParameter = params.queryParameter("parameter");
        assertTrue(requestParameter.isInteger());
        routingContext.response().setStatusMessage(requestParameter.toString()).end();
    });
    testRequest(HttpMethod.GET, "/queryTests/defaultInt", 200, "1");
}
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 62 with Operation

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

the class OpenAPI3ValidationTest method testDefaultStringQueryParameter.

@Test
public void testDefaultStringQueryParameter() 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();
    });
    testRequest(HttpMethod.GET, "/queryTests/defaultString", 200, "aString");
}
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 63 with Operation

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

the class OpenAPI3ValidationTest method testFormArrayParameter.

@Test
public void testFormArrayParameter() throws Exception {
    Operation op = testSpec.getPaths().get("/formTests/arraytest").getPost();
    if (op.getParameters() == null)
        op.setParameters(new ArrayList<>());
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
    loadHandlers("/formTests/arraytest", HttpMethod.POST, false, validationHandler, (routingContext) -> {
        RequestParameters params = routingContext.get("parsedParameters");
        List<String> result = new ArrayList<>();
        for (RequestParameter r : params.formParameter("values").getArray()) result.add(r.getInteger().toString());
        routingContext.response().setStatusMessage(params.formParameter("id").getString() + serializeInCSVStringArray(result)).end();
    });
    String id = "anId";
    List<String> valuesArray = new ArrayList<>();
    for (int i = 0; i < 4; i++) valuesArray.add(getSuccessSample(ParameterType.INT).getInteger().toString());
    String values = serializeInCSVStringArray(valuesArray);
    MultiMap form = MultiMap.caseInsensitiveMultiMap();
    form.add("id", id);
    form.add("values", values);
    testRequestWithForm(HttpMethod.POST, "/formTests/arraytest", FormType.FORM_URLENCODED, form, 200, id + values);
}
Also used : MultiMap(io.vertx.core.MultiMap) 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 64 with Operation

use of io.swagger.v3.oas.models.Operation in project cas by apereo.

the class LoggingConfigurationEndpoint method updateLoggerLevel.

/**
 * Looks up the logger in the logger factory,
 * and attempts to find the real logger instance
 * based on the underlying logging framework
 * and retrieve the logger object. Then, updates the level.
 * This functionality at this point is heavily dependant
 * on the log4j API.
 *
 * @param loggerName  the logger name
 * @param loggerLevel the logger level
 * @param additive    the additive nature of the logger
 */
@WriteOperation
@Operation(summary = "Update logger level for a logger name", parameters = { @Parameter(name = "loggerName", required = true), @Parameter(name = "loggerLevel", required = true), @Parameter(name = "additive") })
public void updateLoggerLevel(@Selector final String loggerName, final String loggerLevel, final boolean additive) {
    val loggerConfigs = getLoggerConfigurations();
    loggerConfigs.stream().filter(cfg -> cfg.getName().equals(loggerName)).forEachOrdered(cfg -> {
        cfg.setLevel(Level.getLevel(loggerLevel));
        cfg.setAdditive(additive);
    });
    this.loggerContext.updateLoggers();
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) Getter(lombok.Getter) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) SneakyThrows(lombok.SneakyThrows) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerFactory(org.slf4j.LoggerFactory) ToStringStyle(org.apache.commons.lang3.builder.ToStringStyle) Level(org.apache.logging.log4j.Level) HashMap(java.util.HashMap) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) StringUtils(org.apache.commons.lang3.StringUtils) InitializingBean(org.springframework.beans.factory.InitializingBean) HashSet(java.util.HashSet) Operation(io.swagger.v3.oas.annotations.Operation) Pair(org.apache.commons.lang3.tuple.Pair) Configurator(org.apache.logging.log4j.core.config.Configurator) Map(java.util.Map) Log4jLoggerFactory(org.apache.logging.slf4j.Log4jLoggerFactory) Resource(org.springframework.core.io.Resource) ResourceUtils(org.apereo.cas.util.ResourceUtils) Logger(org.slf4j.Logger) ResourceLoader(org.springframework.core.io.ResourceLoader) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) lombok.val(lombok.val) Set(java.util.Set) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) Slf4j(lombok.extern.slf4j.Slf4j) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) Environment(org.springframework.core.env.Environment) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) Optional(java.util.Optional) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) ILoggerFactory(org.slf4j.ILoggerFactory) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 65 with Operation

use of io.swagger.v3.oas.models.Operation in project cas by apereo.

the class LoggingConfigurationEndpoint method configuration.

/**
 * Configuration map.
 *
 * @return the map
 */
@ReadOperation
@Operation(summary = "Get logging configuration report")
public Map<String, Object> configuration() {
    val configuredLoggers = new HashSet<>();
    getLoggerConfigurations().forEach(config -> {
        val loggerMap = new HashMap<String, Object>();
        loggerMap.put("name", StringUtils.defaultIfBlank(config.getName(), LOGGER_NAME_ROOT));
        loggerMap.put("state", config.getState());
        if (config.getPropertyList() != null) {
            loggerMap.put("properties", config.getPropertyList());
        }
        loggerMap.put("additive", config.isAdditive());
        loggerMap.put("level", config.getLevel().name());
        val appenders = new HashSet<>();
        config.getAppenders().keySet().stream().map(key -> config.getAppenders().get(key)).forEach(appender -> {
            val builder = new ToStringBuilder(this, ToStringStyle.JSON_STYLE);
            builder.append("name", appender.getName());
            builder.append("state", appender.getState());
            builder.append("layoutFormat", appender.getLayout().getContentFormat());
            builder.append("layoutContentType", appender.getLayout().getContentType());
            if (appender instanceof FileAppender) {
                builder.append(FILE_PARAM, ((FileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, "(none)");
            }
            if (appender instanceof RandomAccessFileAppender) {
                builder.append(FILE_PARAM, ((RandomAccessFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, "(none)");
            }
            if (appender instanceof RollingFileAppender) {
                builder.append(FILE_PARAM, ((RollingFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, ((RollingFileAppender) appender).getFilePattern());
            }
            if (appender instanceof MemoryMappedFileAppender) {
                builder.append(FILE_PARAM, ((MemoryMappedFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, "(none)");
            }
            if (appender instanceof RollingRandomAccessFileAppender) {
                builder.append(FILE_PARAM, ((RollingRandomAccessFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, ((RollingRandomAccessFileAppender) appender).getFilePattern());
            }
            appenders.add(builder.build());
        });
        loggerMap.put("appenders", appenders);
        configuredLoggers.add(loggerMap);
    });
    val responseMap = new HashMap<String, Object>();
    responseMap.put("loggers", configuredLoggers);
    val loggers = getActiveLoggersInFactory();
    responseMap.put("activeLoggers", loggers.values());
    return responseMap;
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) Getter(lombok.Getter) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) SneakyThrows(lombok.SneakyThrows) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerFactory(org.slf4j.LoggerFactory) ToStringStyle(org.apache.commons.lang3.builder.ToStringStyle) Level(org.apache.logging.log4j.Level) HashMap(java.util.HashMap) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) StringUtils(org.apache.commons.lang3.StringUtils) InitializingBean(org.springframework.beans.factory.InitializingBean) HashSet(java.util.HashSet) Operation(io.swagger.v3.oas.annotations.Operation) Pair(org.apache.commons.lang3.tuple.Pair) Configurator(org.apache.logging.log4j.core.config.Configurator) Map(java.util.Map) Log4jLoggerFactory(org.apache.logging.slf4j.Log4jLoggerFactory) Resource(org.springframework.core.io.Resource) ResourceUtils(org.apereo.cas.util.ResourceUtils) Logger(org.slf4j.Logger) ResourceLoader(org.springframework.core.io.ResourceLoader) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) lombok.val(lombok.val) Set(java.util.Set) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) Slf4j(lombok.extern.slf4j.Slf4j) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) Environment(org.springframework.core.env.Environment) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) Optional(java.util.Optional) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) ILoggerFactory(org.slf4j.ILoggerFactory) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) HashMap(java.util.HashMap) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) HashSet(java.util.HashSet) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) Operation(io.swagger.v3.oas.annotations.Operation)

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