swagger-api / swagger-api/swagger-codegen
[any] Excessive memory usage when generating examples
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The json strings generated to populate the example list is done in an exhaustive manner, regardless of usage. If there are recursion or deep hierarchies of models the resulting JSON strings can get massive, leading to excessive memory usage.
With examples generated:

no examples generated:

Swagger-codegen version
Master branch at revision 955ec39bdcf469e03d00143bf57b6a53276dfe8e
Swagger declaration url
https://tripletex.no/v2/swagger.json
Command line used for generation
generate -i https://tripletex.no/v2/swagger.json
--lang java
-c ./config.json
-o ./build/generated
-Dapis -DapiTests=false -DapiDocs=false
-Dmodels -DmodelTests=false -DmodelDocs=false
-DsupportingFiles
config.json being
{
"library": "jersey2",
"dateLibrary": "java8",
"java8": true
}
Steps to reproduce
Generate the client and observe the memory usage.
Related issues/PRs
Possibly #6394
Suggest a fix/enhancement
Override DefaultCodegen#getExamples in all generatores that don't use examples at all.
Or make the example json generation be on demand instead of being generated upfront regardless of their usage.
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
Start at DefaultCodegen#getExamples and compare how the generators use the example list. Reproduce the issue with the Tripletex Swagger declaration and the Java jersey2 command/configuration shown above; done means example JSON is not exhaustively generated when it is unused, without breaking generators that consume examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100