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

fixes #117 #118

Merged
merged 3 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -28,6 +28,7 @@
import io.undertow.Handlers;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -81,7 +82,6 @@ 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());
Expand All @@ -90,6 +90,7 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
if(config.logError) logger.error("ValidationError:" + status.toString());
return;
}

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