Swagger-codegen: Option to turn off @javax.annotation.Generated date in Java Classes

Created on 11 May 2016  路  7Comments  路  Source: swagger-api/swagger-codegen

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.

General

Most helpful comment

You can use the following option:

        hides the timestamp when files were generated

Ref: java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l java

All 7 comments

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

        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
Was this page helpful?
0 / 5 - 0 ratings