Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -155,12 +155,6 @@ private List<OpenApiViolation> validateRequest(
}

private static String readBodyCatchingException(MultiReadContentCachingRequestWrapper request) {
if (!"POST".equalsIgnoreCase(request.getMethod())
&& !"PUT".equalsIgnoreCase(request.getMethod())
&& !"PATCH".equalsIgnoreCase(request.getMethod())) {
return null;
}

try {
return StreamUtils.copyToString(request.getInputStream(), StandardCharsets.UTF_8);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.getyourguide.openapi.validation.api.model.OpenApiViolation;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.web.server.ResponseStatusException;

class OpenApiValidationInterceptorTest extends BaseFilterTest {
Expand Down Expand Up @@ -104,15 +106,16 @@ public void testShouldFailOnRequestViolationWithViolation() {
verifyNoResponseValidation();
}

@Test
public void testShouldIgnoreBodyOnGetRequests() {
var mockData = mockSetup(MockConfiguration.builder().requestBody("{\"field\": 1}}").requestMethod("GET").build());
@ParameterizedTest
@ValueSource(strings = {"GET", "POST", "PUT", "PATCH", "DELETE"})
public void testShouldSupportBodyOnGetRequests(String requestMethod) {
var mockData = mockSetup(MockConfiguration.builder().requestBody("{\"field\": 1}}").requestMethod(requestMethod).build());

httpInterceptor.preHandle(mockData.request(), mockData.response(), new Object());
httpInterceptor.postHandle(mockData.request(), mockData.response(), new Object(), null);
httpInterceptor.afterCompletion(mockData.request(), mockData.response(), new Object(), null);

verifyRequestValidatedAsync(mockData, null);
verifyRequestValidatedAsync(mockData, "{\"field\": 1}}");
verifyResponseValidatedAsync(mockData);
}

Expand Down
Loading