swagger-api / swagger-api/swagger-codegen
[Java] supporting files like ApiClient cannot be generated because of bug in 2.4.6
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Due to a breaking change in 2.4.6 (compared to 2.4.5), generating supporting files like e.g. ApiClient.java that are necessary for producing a working client has become impossible.
Swagger-codegen version
version 2.4.6
Swagger declaration file content or url
any yaml (e.g. petstore).
Command line used for generation
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i http://petstore.swagger.io/v2/swagger.json -l java --library resttemplate -o ../petstore-server
Steps to reproduce
- Use any yaml or json service description (e.g. petstore)
- try to generate a client for language "java", and library "resttemplate"
- observe that NO supporting files have been generated in the output directory (so no ApiClient in the (specified or implicit) invokerPackage)
Related issues/PRs
none
Suggest a fix/enhancement
The problem is with the 2.4.6 version of io.swagger.codegen.DefaultGenerator#configureGeneratorProperties(), specifically line 138 (which was line 130 in 2.4.5).
Whereas the 2.4.5 version was setting the isGenerateSupportingFiles boolean flag to TRUE whenever a non-null system property "supportingFiles" existed, the 2.4.6 version only sets this flag to TRUE when that system property exists, AND is equal to (ignoring case) "true".
The problem with this, is that this system property serves a dual purpose - DefaultGenerator.generateSupportingFiles() interprets it as a comma separated 'whitelist' of supporting files to generate; lines 588 - 594 (of the 2.4.6 version) skip any file to be generated, if its name is not contained within this comma separated list.
So, setting -DsupportingFiles=true does not help in 2.4.6, since the whitelist will be "true" and of course no supporting files match that.
Fix/enhancement: either
- revert the change that was made in 2.4.6, or
- retire the code in lines 588 - 594, or
- use a different property name if the 'whitelist' functionality is to be maintained.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read DefaultGenerator#configureGeneratorProperties() around the 2.4.6 change, then inspect generateSupportingFiles() and its supportingFiles filtering around lines 588–594. Reproduce the Java resttemplate generation command with the petstore definition and verify that supporting files such as ApiClient.java are generated without breaking the whitelist behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100