Skip to content

Commit

Permalink
fixes #117 (#118)
Browse files Browse the repository at this point in the history
* fixes #117

* fixes #117

*  add one more fix for audit the request validation result
  • Loading branch information
GavinChenYan authored and stevehu committed Nov 19, 2019
1 parent 3407a3e commit 9aa9a83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Optional;
import java.util.Set;

import io.undertow.util.Headers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -84,12 +85,13 @@ public Status validateRequest(final NormalisedPath requestPath, HttpServerExchan

Status status = validateRequestParameters(exchange, requestPath, openApiOperation);
if(status != null) return status;

Object body = exchange.getAttachment(BodyHandler.REQUEST_BODY);
// skip the body validation if body parser is not in the request chain.
if(body == null && ValidatorHandler.config.skipBodyValidation) return null;
status = validateRequestBody(body, openApiOperation);

String contentType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE);
if (contentType==null || contentType.startsWith("application/json")) {
Object body = exchange.getAttachment(BodyHandler.REQUEST_BODY);
// skip the body validation if body parser is not in the request chain.
if(body == null && ValidatorHandler.config.skipBodyValidation) return null;
status = validateRequestBody(body, openApiOperation);
}
return status;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,13 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
setExchangeStatus(exchange, STATUS_MISSING_OPENAPI_OPERATION);
return;
}

Status status = requestValidator.validateRequest(requestPath, exchange, openApiOperation);
if(status != null) {
exchange.setStatusCode(status.getStatusCode());
status.setDescription(status.getDescription().replaceAll("\\\\", "\\\\\\\\"));
exchange.getResponseSender().send(status.toString());
setExchangeStatus(exchange, status.getCode());
if(config.logError) logger.error("ValidationError:" + status.toString());
return;
}

if(config.validateResponse) {
validateResponse(exchange, openApiOperation);
}
Expand Down

0 comments on commit 9aa9a83

Please sign in to comment.