swagger-api / swagger-api/swagger-codegen

[JAVA] [Spring] Example Generator does not process relative reference if used in multiple places

Open
#5,666 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted Issue: Bug Server: Java Server: Spring
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Example Generator fails to resolve the processedModels if used more than once. Any time a processed model needs to be re-used, the example generator returns an empty string. Hence, the first occurrence of a model returns the example values but thereafter, the repeated occurrence of the model gets an empty string.

Swagger-codegen version

2.3.0 (possibly in 2.2.3 as well)

Swagger declaration file content or url

If a JSON (originally referred in the response section of swagger spec), say sku_fulfillment.json has reference to JSON A (specialDelivery_object.json) and JSON B (download_object.json) and both JSON A and JSON B has reference to JSON C (messages_object.json), when the response is generated, only JSON A object gets populated with JSON C. JSON B object in response has JSON C object as null.

sku_fulfillment.json -> https://gist.github.com/elizabetht/d37801463f56f38ec5ab3266602fcc27
specialDelivery_object.json -> https://gist.github.com/elizabetht/c31a9fadf1225da56b452ed7203f7249
download_object.json -> https://gist.github.com/elizabetht/8aabae4fe2ce8c913f6741691d66b713
messages_object.json ->https://gist.github.com/elizabetht/043b3cb886d28883742baace398b3dd6

Command line used for generation

language = spring

Steps to reproduce

If a JSON (originally referred in the response section of swagger spec), say sku_fulfillment.json has reference to JSON A (specialDelivery_object.json) and JSON B (download_object.json) and both JSON A and JSON B has reference to JSON C (messages_object.json), when the response is generated, only JSON A object gets populated with JSON C. JSON B object in response has JSON C object as null.

Suggest a Fix

resolveModelToExample in ExampleGenerator.java returns empty string when a given model is processed. This is why the first instance of the object has the example populated where as the rest of the references get null. This block of code should instead return model example (which should be populated in section where the model is checked against the properties)

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 in ExampleGenerator.java at resolveModelToExample and reproduce the nested-reference case using the linked JSON declarations. Trace how a processed model is handled on its first and subsequent uses; done means repeated references, including JSON C under both JSON A and JSON B, receive populated examples rather than null or empty output.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.