swagger-api / swagger-api/swagger-codegen

[any] Excessive memory usage when generating examples

Open
#10,199 0 comments 0 reactions 0 assignees View on GitHub

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:
With examples generated

no 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.