Search in sources :

Example 1 with SwaggerOperation

use of com.networknt.swagger.SwaggerOperation in project light-rest-4j by networknt.

the class RequestValidator method validatePathParameters.

private Status validatePathParameters(final NormalisedPath requestPath, final SwaggerOperation swaggerOperation) {
    Status status = null;
    for (int i = 0; i < swaggerOperation.getPathString().parts().size(); i++) {
        if (!swaggerOperation.getPathString().isParam(i)) {
            continue;
        }
        final String paramName = swaggerOperation.getPathString().paramName(i);
        final String paramValue = requestPath.part(i);
        final Optional<Parameter> parameter = swaggerOperation.getOperation().getParameters().stream().filter(p -> p.getIn().equalsIgnoreCase("PATH")).filter(p -> p.getName().equalsIgnoreCase(paramName)).findFirst();
        if (parameter.isPresent()) {
            status = parameterValidators.validate(paramValue, parameter.get());
        }
    }
    return status;
}
Also used : Status(com.networknt.status.Status) java.util(java.util) Logger(org.slf4j.Logger) BodyParameter(io.swagger.models.parameters.BodyParameter) HttpServerExchange(io.undertow.server.HttpServerExchange) LoggerFactory(org.slf4j.LoggerFactory) SwaggerOperation(com.networknt.swagger.SwaggerOperation) Parameter(io.swagger.models.parameters.Parameter) HeaderValues(io.undertow.util.HeaderValues) BodyHandler(com.networknt.body.BodyHandler) Objects.requireNonNull(java.util.Objects.requireNonNull) Status(com.networknt.status.Status) NormalisedPath(com.networknt.swagger.NormalisedPath) ParameterValidators(com.networknt.validator.parameter.ParameterValidators) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter)

Aggregations

BodyHandler (com.networknt.body.BodyHandler)1 Status (com.networknt.status.Status)1 NormalisedPath (com.networknt.swagger.NormalisedPath)1 SwaggerOperation (com.networknt.swagger.SwaggerOperation)1 ParameterValidators (com.networknt.validator.parameter.ParameterValidators)1 BodyParameter (io.swagger.models.parameters.BodyParameter)1 Parameter (io.swagger.models.parameters.Parameter)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 HeaderValues (io.undertow.util.HeaderValues)1 java.util (java.util)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1