openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[REQ][Java][Spring] Add option to disable @Validated annotation at class level for Spring generator with useBeanValidation

Open takashno opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe.

When using the "spring" generator with the "useBeanValidation" option enabled, the generated code adds the @Validated annotation at the class level for controllers. However, this causes compatibility issues with the validation mechanism introduced in Spring Framework 6.x.x and later. Specifically, Spring's official documentation recommends avoiding @Validated at the class level for WebFlux controllers.

Related official documentation:
https://docs.spring.io/spring-framework/reference/web/webflux/controller/ann-validation.html

Additionally, this issue has been discussed on the Spring Framework side:
https://github.com/spring-projects/spring-framework/issues/34556

Describe the solution you'd like

I would like an option to disable or control the generation of the @Validated annotation at the class level when generating Spring controllers using the "spring" generator with "useBeanValidation" enabled.

Describe alternatives you've considered

  • Manually removing @Validated from generated classes every time code is generated.
  • Using a custom template to override the default behavior, but this adds maintenance overhead.

Additional context

This change would improve compatibility with Spring Framework 6.x.x+ and align with Spring's official guidelines.

takashno avatar Mar 16 '25 02:03 takashno

This change would improve compatibility with Spring Framework 6.x.x+ and align with Spring's official guidelines.

looks like a very good feature. I wonder if you've time to file a PR to add an option to start with, and we will review accordingly to get it merged.

wing328 avatar Mar 16 '25 08:03 wing328

@wing328

Thank you for your response. I’ve been relying on this tool for a long time, and I truly believe it will continue to be widely used across many projects. I will make some time to work on this and submit a PR.

takashno avatar Mar 16 '25 08:03 takashno

glad to hear you've been using this tool for a long time.

look forward to your PR

wing328 avatar Mar 16 '25 08:03 wing328

@wing328

I have created a PR with some improvements.
I would appreciate it if you could take a look.
Thank you!

takashno avatar Mar 16 '25 12:03 takashno