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

[Suggestion] Remove timestamp from auto-generated code/documentation

Open wing328 opened this issue 8 years ago • 18 comments

In the coming major release 2.2.0, we want to remove {{generatedDate}} from the mustache template as this will introduce a lot of noise when it comes to reviewing the auto-generated code/documentation. Here is an example:

 package io.swagger.client;

 [email protected](value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-04T21:04:39.523+08:00")
 [email protected](value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-08T18:45:27.896+02:00")
  public class StringUtil {
    /**
     * Check if the given array contains the given value (with case-insensitive comparison).

If anyone has a good reason to keep it in the auto-generated timestamp, please reply to let us know.

wing328 avatar Jun 08 '16 17:06 wing328

I would love to have them static, constant diffs are annoying. Related might be the auto documented docs, I noticed a few times that fields changed order, which gives unnecessary diffs as well.

Edubits avatar Jun 08 '16 17:06 Edubits

Right. The authentication settings are not in any order so we need to sort them alphabetically to avoid the noise due to random order.

wing328 avatar Jun 08 '16 17:06 wing328

There is an existing hideGenerationTimestamp property that can be used for this. We just need to put it in the templates and use -DhideGenerationTimestamp=true to generate the samples

cbornet avatar Jun 08 '16 17:06 cbornet

Right. The option is for Java only at the moment: https://github.com/swagger-api/swagger-codegen/blob/691aa53d5af958a6613139ca77bbc6038eeea6ca/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java#L49

We can make it a general option to make it available in other langauges.

My suggestion is to remove the timestamp from the template without hideGenerationTimestamp

wing328 avatar Jun 08 '16 18:06 wing328

Previous related discussion: #2318. I'm not sure why that was closed – it looks like the original issue author just modified its own templates and thus lost interest?

ePaul avatar Jun 08 '16 19:06 ePaul

I think the default should be to have no timestamp. I'm not sure if there should be an option to include it.

By the way, I think what could be useful would be to include the Swagger-Codegen version in the generated files. While for the samples to be committed in our repository this should also be disabled (for the same reason as disabling the timestamps), having it on by default in the online generator would be useful for identifying the version in bug reports.

ePaul avatar Jun 08 '16 19:06 ePaul

We could set hideGenerationTimestamp to true by default ?

cbornet avatar Jun 08 '16 19:06 cbornet

@ePaul instead of stamping every generated files with the swagger-codegen version. What about generating a file (e.g. .swagger-codegen-version) instead?

I agree including the swagger codegen version in the API clients or servers stubs will help us more easily troubleshoot issue.

wing328 avatar Jun 09 '16 08:06 wing328

@wing328 either this, or putting it into the generated README (if there is some) might be better than putting it in every file, yes.

ePaul avatar Jun 09 '16 15:06 ePaul

The typescript-angular/npm examples have a date/time in the package version for NPM. Not sure how to handle that:

{
  "name": "@swagger/angular2-typescript-petstore",
  "version": "0.0.1-SNAPSHOT.201703251242",
  "description": "swagger client for @swagger/angular2-typescript-petstore",

ePaul avatar Mar 26 '17 16:03 ePaul

Changes like these I get each time I update typescript-angular2/npm or typescript-jquery/npm. This needs to be solved. Unfortunately I don't know much about NPM to tell how a snapshot package version should look like.

diff --git a/samples/client/petstore/typescript-angular2/npm/README.md b/samples/client/petstore/typescript-angular2/npm/README.md
index 9bfa85d..e3efc3e 100644
--- a/samples/client/petstore/typescript-angular2/npm/README.md
+++ b/samples/client/petstore/typescript-angular2/npm/README.md
@@ -1,4 +1,4 @@
-## @swagger/[email protected]
+## @swagger/[email protected]
 
 ### Building
 
@@ -19,7 +19,7 @@ navigate to the folder of your consuming project and run one of next commando's.
 _published:_
 
 ```
-npm install @swagger/[email protected] --save
+npm install @swagger/[email protected] --save
 ```
 
 _unPublished (not recommended):_
diff --git a/samples/client/petstore/typescript-angular2/npm/package.json b/samples/client/petstore/typescript-angular2/npm/package.json
index ae0d67d..bd8d8b6 100644
--- a/samples/client/petstore/typescript-angular2/npm/package.json
+++ b/samples/client/petstore/typescript-angular2/npm/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@swagger/angular2-typescript-petstore",
-  "version": "0.0.1-SNAPSHOT.201703211709",
+  "version": "0.0.1-SNAPSHOT.201703281717",
   "description": "swagger client for @swagger/angular2-typescript-petstore",
   "author": "Swagger Codegen Contributors",
   "keywords": [
diff --git a/samples/client/petstore/typescript-jquery/npm/package.json b/samples/client/petstore/typescript-jquery/npm/package.json
index 89b35a0..a01d6b7 100644
--- a/samples/client/petstore/typescript-jquery/npm/package.json
+++ b/samples/client/petstore/typescript-jquery/npm/package.json
@@ -1,6 +1,6 @@
 {
     "name": "@swagger/angular2-typescript-petstore",
-    "version": "0.0.1-SNAPSHOT.201703061507",
+    "version": "0.0.1-SNAPSHOT.201703281717",
     "description": "JQuery client for @swagger/angular2-typescript-petstore",
     "main": "api.js",
     "scripts": {

ePaul avatar Mar 28 '17 16:03 ePaul

@ePaul thanks for the details. I'll take a look later

wing328 avatar Mar 30 '17 02:03 wing328

@wing328 - its been more than two years, and somehow this popped up again after going to version 5.

All files have the "built on" in them. Is there any supported way to disable this?

ex: built on: 2020-12-22T19:46:39.409Z

jblayneyXpanxion avatar Dec 22 '20 19:12 jblayneyXpanxion

hideGenerationTimestamp=true does not work.

As the reason was mentioned earlier, it creates so much noise in all the generated files.

I am using 5.3.0v for Spring

ramjia2z avatar Oct 25 '21 08:10 ramjia2z

Any update for this? I'm working on openapi-generator-cli-6.3.0.jar, the generated java code still cannot erase the date = XXX from the @Generated annotation.

ljhazy avatar Mar 14 '23 14:03 ljhazy

Not sure how to pass the parameter to the client, I tried:

yarn openapi-generator-cli generate -i my.yaml -g java -o ./sdk -DhideGenerationTimestamp=true

but I get:

[error] Found unexpected parameters: [-DhideGenerationTimestamp=true]

andresesfm avatar Aug 12 '23 04:08 andresesfm

I ended up adding this to my generation script:

find /path/to/folder -type f -name "*.java" -exec sed -i '/^@javax\.annotation\.Generated/d' {} \;

andresesfm avatar Aug 12 '23 04:08 andresesfm

Any update for this? I'm working on openapi-generator-cli-6.3.0.jar, the generated java code still cannot erase the date = XXX from the @generated annotation.

@ljhazy Hi ljhazy,Having seen your comment, I would like to ask if it is possible to delete all @ jakarta. annotation. Generated(), including value and date.

jinyangyang222 avatar Aug 31 '23 02:08 jinyangyang222