swagger-codegen
swagger-codegen copied to clipboard
useBeanValidation set to false does not work. Annotations javax.validation.* are still produced
Description
I am trying to turn off bean validation, so not @Validated would be used on generated model. I can't. When I set <useBeanValidation>false</useBeanValidation> it is completely ignored.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Use the plugin configuration above and have the code generated. It will still contain @Validated annotations, plus more javax.validation.*
Related issues/PRs
I haven't found any.
Suggest a fix/enhancement
Please advise, or fix it.
Reproducable with https://github.com/slarti-b/swagger-bean-validation-demo.git setting useBeanValidation to false still generates e.g. @Valid public DemoSub getReqSub() in src/gen/java/main/com/carus/api/bug/models/DemoBody.java reproduced with versions 2.2.3, 2.3.1 and 2.4.0
Same issue in 2.4.2.
My investigations took me to finding that probably this variable has wrong type.
When debugging operations it appears as "useBeanValidation" : "false".
When I changed SpringCodegen to always writeBack its value: writePropertyBack(USE_BEANVALIDATION, useBeanValidation); it started working as expected and debugOperations prints "useBeanValidation" : false.
The temporary(i hope) fix would be to :
- extend
SpringCodegenclass - override
processOptswhich executes super.processOpts() and unconditionally:writePropertyBack(USE_BEANVALIDATION, useBeanValidation); - use this class as language for swagger-codegen
this seems to work as expected in my environment.
I also confirm the issue for swagger-codegen-maven-plugin 3.0.19
Does anyone solve this issue? I'm getting this error with swagger-codegen-maven-plugin 3.0.22
The same issue with MicronautCodegen 3.0.25
When is this going to be fixed?
Version 3.0.51 still contains this bug. A fix would be highly appreciated.