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

Option to turn off @javax.annotation.Generated date in Java Classes

Open jasonboggess opened this issue 8 years ago • 9 comments

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 avatar May 11 '16 15:05 jasonboggess

@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.

wing328 avatar May 14 '16 16:05 wing328

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 avatar Oct 07 '16 16:10 willgorman

@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.

wing328 avatar Oct 07 '16 16:10 wing328

@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

cbornet avatar Oct 07 '16 16:10 cbornet

@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.

kpradeepkumarreddy avatar Dec 01 '16 05:12 kpradeepkumarreddy

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

wing328 avatar Dec 01 '16 06:12 wing328

@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

tgraupmann avatar Apr 17 '17 20:04 tgraupmann

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

bayuwijdev avatar Mar 02 '22 03:03 bayuwijdev

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

k163377 avatar Apr 10 '24 14:04 k163377