swagger-api/swagger-codegen

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

Open

#4393 aperta il 14 dic 2016

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)HTML (5474 fork)batch import
Enhancement: FeatureServer: Nodejshelp wanted

Metriche repository

Star
 (12.701 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor