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

validation: handler/filter for lambda routes + remove MvcValidator #3522

Merged
merged 1 commit into from
Sep 8, 2024

Conversation

jknack
Copy link
Member

@jknack jknack commented Sep 7, 2024

  • Remove MvcValidator. Merge content into BeanValidator
  • Rename BeanValidator.validate to BeanValidator.apply (avoid method name conflict)
  • Creates BeanValidator.validate() route handler/filter which intercept calls to HTTP request object and run validator
  • TODO: if we agreed on merging of MvcValidator we can remove/get rid of jooby-validation module

There two ways of using validator on lambda routes:

{
    get("/do", validate(ctx -> ctx.query(Bean.class)));
}

Or with filter:

{
    use(validate());
    get("/do", ctx -> ctx.query(Bean.class));
}

@jknack
Copy link
Member Author

jknack commented Sep 7, 2024

@SentryMan @kliushnichenko one more

@jknack jknack force-pushed the morevalidation branch 2 times, most recently from 1ab5620 to ace4841 Compare September 7, 2024 21:51
@kliushnichenko
Copy link
Contributor

the developer experience is much better with a filter, but, the price is reflection/proxy usage, are we fine with it?
I remember you were discussing GraalVM support, is it still on the roadmap?

@jknack
Copy link
Member Author

jknack commented Sep 8, 2024

GraalVM

Nothing more was done for long time.

Let me remove reflection. I'm just lazy sometimes.

@jknack
Copy link
Member Author

jknack commented Sep 8, 2024

@kliushnichenko without reflection

- Remove `MvcValidator`. Merge content into `BeanValidator`
- Rename BeanValidator.validate to BeanValidator.apply (avoid method name conflict)
- Creates BeanValidator.validate() route handler/filter which intercept calls to HTTP request object and run validator
- TODO: if we agreed on merging of MvcValidator we can remove/get rid of `jooby-validation` module
@jknack jknack added this to the 3.3.1 milestone Sep 8, 2024
@jknack jknack merged commit a7c0971 into 3.x Sep 8, 2024
5 checks passed
@kliushnichenko
Copy link
Contributor

It's a bit late, but
I realized that if the project shares both approaches (mvc/lambda)
and uses filter use(validate())
that means that MVC route beans will be validated twice...

Sharing mvc/lambda is probably not a common case, but still realistic/possible.
Maybe we should remove the filter, and keep only the handler, bc behavior is quite odd.
Or at least add a note in the documentation

@jknack
Copy link
Member Author

jknack commented Sep 9, 2024

Feel it is an odd case (like you said), but we can probably do something to fix it.

can you work and mentioned on documentation?

@jknack jknack deleted the morevalidation branch September 14, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants