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

Support fail on request/response violation #3

Merged
merged 8 commits into from
May 25, 2023
Merged

Conversation

pboos
Copy link
Collaborator

@pboos pboos commented May 23, 2023

This adds support for failing the request on violations.
In case of a request violation it will not execute the endpoint logic at all.

Configuration in application.properties with

openapi.validation.should-fail-on-request-violation=true
openapi.validation.should-fail-on-response-violation=true

Note for reviewing: The WebFilter and HttpFilter in spring 2.7 modules are copy paste from the spring 3.0 ones with just the changes needed for spring 2.7 (different imports due to different package or class name).

@pboos pboos marked this pull request as ready for review May 23, 2023 14:58
@pboos pboos requested review from a team and ursulean May 23, 2023 14:58
@pboos pboos changed the title Support fail on request/response violation in webflux Support fail on request/response violation May 24, 2023
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

class OpenApiValidationWebFilterTest {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Very similar to the other test. Same approach used. Differences are mainly the mocking.


@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Changes here are copy paste from the non spring 2.7.
Different imports and/or minimal code changes like HttpStatus vs HttpStatusCode which changed in spring boot .

@@ -48,31 +51,107 @@ private Mono<Void> decorateWithValidation(ServerWebExchange exchange, WebFilterC

var serverWebExchange = exchange.mutate().request(requestDecorated).response(responseDecorated).build();

var alreadyDidRequestValidation = validateRequestWithFailOnViolation(requestMetaData, requestDecorated);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Changes here are copy paste from the non spring 2.7.
Different imports and/or minimal code changes like HttpStatus vs HttpStatusCode which changed in spring boot .

@pboos pboos merged commit d70f4b9 into main May 25, 2023
@pboos pboos deleted the feature/fail-on-violation branch June 9, 2023 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants