swagger-codegen
swagger-codegen copied to clipboard
Option to turn off @javax.annotation.Generated date in Java Classes
Currently, every time we generate new classes, the following headers is added to the class:
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringMVCServerCodegen", date = "2016-05-11T11:35:54.190-04:00")
Git picks up the change in date, which adds a lot of noise every time the code is regenerated. Would be nice to have an option to turn this off.
@jasonboggess thanks for the feedback. In the coming release, we plan to make all the date-related output optional to reduce noise to git or other diff tools.
It looks like there's an undocumented hideGenerationTimestamp
option that worked for me, at least with the Jersey 2 server generation. It removes the @Generated
annotation completely though.
@willgorman it's documented in config-help
, e.g.
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l java
but not all generators have implemented this option yet. If you want to help out, please let us know.
@Generated
is problematic on android so I think it should be totally removable for java clients.
For servers, we could probably remove only the date
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-12-01T05:40:15.666+05:30")
@javax.annotation.Generated is causing error in android. I had generated the code for java client (okhttp-gson library). I have also added the following gradle dependency for resolving @javax.annotation.Generated compile group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3'
then i'm getting the following error:-
Error:Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code. This is caused by library dependencies that have been compiled using Java 8 or above. If you are using the 'java' gradle plugin in a library submodule add targetCompatibility = '1.7' sourceCompatibility = '1.7' to that submodule's build.gradle file.
=> when i commented the @javax.annotation.Generated lines, everything is working fine. Is there a way to avoid those lines when i'm generating code.
You can use the following option:
hideGenerationTimestamp
hides the timestamp when files were generated
Ref: java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l java
@kpradeepkumarreddy Your dex error can be solved by upgrading your build.gradle Android API to 21. You'll want to close the project, clear your build folders, and rebuild after that.
It worked for me. https://github.com/swagger-api/swagger-codegen/compare/master...tgraupmann:master
Ref:
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar -DhideGenerationTimestamp=true
Add hideGenerationTimestamp=true in --additional-properties.
- npx @openapitools/openapi-generator-cli generate
-i be-service-auth/openapi.yaml
-g java -o generated-java/ --additional-properties=pubName=genapi,hideGenerationTimestamp=true
I share a method I learned from a colleague.
By placing an empty file named generatedAnnotation.mustache
in any directory and optionally specifying -t ${path-to-dir}
, the generation of that annotation is suppressed.
This overrides the template used to generate the Generated
annotation.
https://github.com/search?q=repo%3AOpenAPITools%2Fopenapi-generator+generatedAnnotation.mustache+language%3AMustache&type=code
See the documentation for the meaning of the -t
option.
https://openapi-generator.tech/docs/usage/#generate