Open rhalaly opened 4 years ago
When the API returns C# tuple like: return this.Ok(("key", "value")); ASP is returning the object as JSON:
return this.Ok(("key", "value"));
{ "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).
i
I
So, actually the generated TypeScript cannot access to the object fields and gets undefined...
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
Item1
You need to change the nswag serializer setting to upper camel case (contract resolver).
When the API returns C# tuple like:
return this.Ok(("key", "value"));
ASP is returning the object as JSON:But NSwag generate this object as an interface:
Note the difference of uppercase and lowercase letters (
i
andI
).So, actually the generated TypeScript cannot access to the object fields and gets
undefined
...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