swagger-api/swagger-codegen

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

Open

#4,393 opened on Dec 14, 2016

View on GitHub
 (1 comment) (0 reactions) (0 assignees)HTML (12,701 stars) (5,474 forks)batch import
Enhancement: FeatureServer: Nodejshelp wanted

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