RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.69k stars 1.24k forks source link

Generating tuples #2604

Open rhalaly opened 4 years ago

rhalaly commented 4 years ago

When the API returns C# tuple like: return this.Ok(("key", "value")); ASP is returning the object as JSON:

{
    "Item1": "key",
    "Item2: "Value"
}

But NSwag generate this object as an interface:

export interface ValueTupleOfStringAndString {
    item1: string;
    item2: string;
}

Note the difference of uppercase and lowercase letters (i and I).

So, actually the generated TypeScript cannot access to the object fields and gets undefined...

obj.item1 // returns undefined
obj.Item1 // returns "key" 

In JavaScript you can read the Item1 since it not enforce the developer to use the defined props, but in TypeScript you cannot get the real values

RicoSuter commented 4 years ago

You need to change the nswag serializer setting to upper camel case (contract resolver).