Search in sources :

Example 1 with Parameter

use of com.networknt.oas.model.Parameter in project light-rest-4j by networknt.

the class RequestValidator method validatePathParameters.

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

Aggregations

BodyHandler (com.networknt.body.BodyHandler)1 Parameter (com.networknt.oas.model.Parameter)1 RequestBody (com.networknt.oas.model.RequestBody)1 Status (com.networknt.status.Status)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