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

Doc: Support for validation in WebFlux.fn [SPR-17401] #21934

Closed
spring-issuemaster opened this Issue Oct 18, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Oct 18, 2018

Ankur Pathak opened SPR-17401 and commented

Well said, documnetation for Spring Web Flux functioal is just great as compared to controller

style. But it keeps silence on saying how to perform validation with Functional Style.

Either we should have documentation improvement mentioning how validation will be done

with functional style or we should have dedicate support for it.


Affects: 5.0.10, 5.1 GA, 5.1.1

Referenced from: commits 15f8863

1 votes, 3 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Nov 4, 2018

rozagerardo commented

Hi! I'm a Baeldung author, and I've worked on an article related to this topic:

https://www.baeldung.com/spring-functional-endpoints-validation

In there I show readers how they can implement Spring validations with a simple, clean and DRY approach.

In a nutshell, I suggest the following steps to run validations in functional endpoints:

  1. Implement Spring Validators to evaluate your resources
  2. Create an abstract class (the AbstractValidationHandler) with the basic procedure that any handler will follow when processing a request, leaving up to the children classes what to do when the data is valid
  3. Make your request handler classes extend this abstract class, implementing this abstract method, stating the body it will be expecting, and what validator needs to be used to validate it

I'm thinking it would be nice for Spring to provide an AbstractValidationHandler out-of-the-box for users to use when they need to run validations in their endpoints.

Even though there are probably several aspects on the abstract class that should be refactored so as to be suitable for any scenario, I think it might be a good starting point.

Note: As I explain in the post, creating custom validators can be omitted since we can add bean validation annotations to our resource and inject the default Spring Validator provided by the LocalValidatorFactoryBean bean to our handler.

Of course, if we decide that such a class would be in fact useful, I'd like to work on its development myself, if that's possible.

Cheers!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Nov 30, 2018

Rossen Stoyanchev commented

rozagerardo thanks for the link to the article. The base class isn't providing enough value IMO to justify the rigidity of having to extend a base class. Delegation should work just as well and let you extend any class you want. In any case such a change is beyond the scope for the request.

Ankur Pathak, in the functional style you get the body object back and it's up to you to validate it. You can use facilities available in the Spring Framework to do that, as shown in the article by rozagerardo.

I guess what we can do in the docs is to provide brief guidance on this with pointers to relevant information.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Nov 30, 2018

Rossen Stoyanchev commented

Commit #15f886.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Nov 30, 2018

rozagerardo commented

Cool thanks for the feedback Rossen Stoyanchev Good work btw (y)

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment