swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

useBeanValidation set to false does not work. Annotations javax.validation.* are still produced

Open liqidator opened this issue 7 years ago • 8 comments

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
io.swagger swagger-codegen-maven-plugin 2.3.1 generate-java-server generate ${basedir}/src/main/resources/api/pisp-api-swagger.yaml spring ${swagger.debug} Gen ${project.parent.name} /src/main/java generated.rest.api generated.rest.model generated.rest spring-boot java8 true true false true false true true false false false true ${swagger.debug} ${swagger.debug} ${swagger.debug}
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.

liqidator avatar Apr 10 '18 11:04 liqidator

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

joergreichert avatar Dec 10 '18 10:12 joergreichert

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.

slawekslawek avatar Mar 19 '19 13:03 slawekslawek

The temporary(i hope) fix would be to :

  1. extend SpringCodegen class
  2. override processOpts which executes super.processOpts() and unconditionally: writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
  3. use this class as language for swagger-codegen

this seems to work as expected in my environment.

slawekslawek avatar Mar 19 '19 14:03 slawekslawek

I also confirm the issue for swagger-codegen-maven-plugin 3.0.19

kdebski85 avatar May 14 '20 10:05 kdebski85

Does anyone solve this issue? I'm getting this error with swagger-codegen-maven-plugin 3.0.22

gilvangobbato avatar Jan 31 '21 18:01 gilvangobbato

The same issue with MicronautCodegen 3.0.25

VSamokhin avatar May 27 '21 15:05 VSamokhin

When is this going to be fixed?

arvindkgs avatar May 13 '22 05:05 arvindkgs

Version 3.0.51 still contains this bug. A fix would be highly appreciated.

alha96 avatar Mar 22 '24 11:03 alha96