Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed validation of path parameters and query parameters #68

Merged
merged 2 commits into from
Jan 22, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URLDecoder;
import java.util.Collection;
import java.util.Optional;

Expand Down Expand Up @@ -123,7 +124,16 @@ private Status validatePathParameters(final NormalisedPath requestPath, final Op
}

final String paramName = openApiOperation.getPathString().paramName(i);
final String paramValue = requestPath.part(i);

String decodeParamValue = null;

try {
decodeParamValue = URLDecoder.decode(requestPath.part(i), "UTF-8");
} catch (Exception e) {
logger.info("Path parameter cannot be decoded, it will be used directly");
}

final String paramValue = (decodeParamValue == null) ? requestPath.part(i) : decodeParamValue;
whoamnick marked this conversation as resolved.
Show resolved Hide resolved

final Optional<Parameter> parameter = openApiOperation.getOperation().getParameters()
.stream()
Expand Down Expand Up @@ -166,7 +176,7 @@ private Status validateQueryParameter(final HttpServerExchange exchange,
if(queryParameter.getRequired()) {
return new Status(VALIDATOR_REQUEST_PARAMETER_QUERY_MISSING, queryParameter.getName(), openApiOperation.getPathString().original());
}
} else {
} else if (queryParameterValues.size() < 2) {

whoamnick marked this conversation as resolved.
Show resolved Hide resolved
Optional<Status> optional = queryParameterValues
.stream()
Expand All @@ -176,6 +186,12 @@ private Status validateQueryParameter(final HttpServerExchange exchange,
if(optional.isPresent()) {
return optional.get();
}
} else {
Status status = schemaValidator.validate(queryParameterValues, Overlay.toJson((SchemaImpl)queryParameter.getSchema()));
Optional<Status> optional = Optional.ofNullable(status);
if(optional.isPresent()) {
return optional.get();
whoamnick marked this conversation as resolved.
Show resolved Hide resolved
}
}
return null;
}
Expand Down