swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.08k stars 6.03k forks source link

[aspnetcore] server generation in aspnetcore assigns wrong value to exampleJson #8892

Open JohnBoncek opened 6 years ago

JohnBoncek commented 6 years ago
Description

Using aspnetcore code gen on the Swagger API specified below assigns wrong value to exampleJson in DefaultApi.cs. This is cut down as far as I can to show just the problem. This is a problem because I was planning to use this value in testing / demo code. (Yes, it can be hand-edited but that defeats the purpose of code gen and the real version is much larger.)

Here is the Example Value / Model output, which is correct:

{ "aa_list": [ { "list": [ { "aa_position": 0 }, { "aa_position": 1 } ] } ] }

Here is the corresponding JSON example in the aspnetcore code:

        exampleJson = "{\n  \"aa_list\" : [ {\n    \"list\" : [ {\n      \"aa_position\" : 0\n    }, {\n      \"aa_position\" : 1\n    } ]\n  }, {\n    \"list\" : [ {\n      \"aa_position\" : 0\n    }, {\n      \"aa_position\" : 1\n    } ]\n  } ]\n}";

The aspnetcore code has the "list" member and its entire contents duplicated.

Swagger-codegen version

SwaggerHub (app.swaggerhub.com)

Swagger declaration file content or url

https://app.swaggerhub.com/apis/JohnBoncek/ArrayProblemRepro/1

Command line used for generation

No command line.

Steps to reproduce

In SwaggerHub at the above URL, choose Export > Server Stub > aspnetcore and examine the generated code in src\IO.Swagger\Controllers\DefaultApi.cs.

Related issues/PRs

None known.

Suggest a fix/enhancement

Generate the correct code.

JohnBoncek commented 6 years ago

The Example Value / Model output was nicely indented as I pasted it in. How do I prevent it being outdented all to the edge in the future?