swagger-api / swagger-api/swagger-codegen

[NODE-SERVER] Should generate multiple examples of same type

Open
#4,393 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature help wanted Server: Nodejs
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

NodeJS Server stub does not generate multiple entries for the same type when the reference type is placed at the same level. In such cases, codegen will only generate the stub for the first case.

Swagger-codegen version

2.2.1

Swagger declaration file content or url

The following swagger definition extract should produce a TransportVehicle json for airplanes, boats and cars.

                "airplanes": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/TransportVehicle"
                    }
                },
                "boats": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/TransportVehicle"
                    }
                },
                "cars": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/TransportVehicle"
                    }
                }

When executed we get:

"airplanes": [ {
  "name" : "abcdef",
  "description": "abcdef"
} ],
"boats": [
  ""
],
"cars": [
  ""
]

Command line used for generation
java -jar swagger-codegen-cli.jar generate -i swagger.json -l nodejs-server -o stub
Steps to reproduce

Create a swagger endpoint with more than one variable reference to the same type at the same field level. Generate stub using command above.

Related issues

None found.

Suggest a Fix

The issue seems to be in the mechanism used to prevent reference type recursion in ExampleGenerator.

This is not just preventing recursion, its also preventing other instances of the same type from being generated.

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 modules/swagger-codegen/src/main/java/io/swagger/codegen/examples/ExampleGenerator.java around lines 137-139, where reference recursion is prevented. Reproduce with the supplied Swagger definition and the nodejs-server generation command. Done means airplanes, boats, and cars each receive a generated TransportVehicle example instead of empty entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, node.js
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.