swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.03k stars 6.03k forks source link

[typescript-*] Bug - Model data is different when using custom template files #4537

Closed thegecko closed 7 years ago

thegecko commented 7 years ago
Description

Fully qualified enum names don't work when overriding template files. This may be an issue broader than just enums and just the typescript language, but I haven't checked beyond the repro below.

Swagger-codegen version

Issue is with v2.2.1, not aware if this is a regression

Swagger declaration file content or url

http://petstore.swagger.io/v2/swagger.json

Command line used for generation

this works:

java -jar swagger-codegen-cli-2.2.1.jar generate -l typescript-fetch -o ./out -i http://petstore.swagger.io/v2/swagger.json

after adding the same template to a folder template, this produces a different output:

java -jar swagger-codegen-cli-2.2.1.jar generate -l typescript-fetch -o ./out -i http://petstore.swagger.io/v2/swagger.json -t template/
Steps to reproduce
  1. execute:
    java -jar swagger-codegen-cli-2.2.1.jar generate -l typescript-fetch -o ./out -i http://petstore.swagger.io/v2/swagger.json
  2. Look at the generated output in out/api.ts and note the enum names, e.g. line 74:
    export type OrderStatusEnum = "placed" | "approved" | "delivered";
  3. Copy the same template contents and save it into a custom template file:
    template/api.mustache
  4. re-run the codegen using the custom template instead:
    java -jar swagger-codegen-cli-2.2.1.jar generate -l typescript-fetch -o ./out -i http://petstore.swagger.io/v2/swagger.json -t template/
  5. Look at the generated output again and now notice the enum names are no longer fully qualified and clash with each other. e.g., line 74:
    export type StatusEnum = "placed" | "approved" | "delivered";

Expected: custom templates should have exactly the same data models passed in.

Related issues

None aware of

Suggest a Fix

It may be that the custom templates are somehow rendered without postProcessModels being run.

wing328 commented 7 years ago

@thegecko thanks for reporting the issue, which is pretty weird...

Do you mind giving it another try with the latest master of swagger codegen by building the JAR locally (mvn clean package) to see if the latest code base still has the same issue?

thegecko commented 7 years ago

Thanks, looks like this is fixed in 2.2.2-SNAPSHOT

wing328 commented 7 years ago

@thegecko thanks for doing a test to confirm.

(If you like Swagger Codegen, please upvote our ProductHunt page)