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

Typescript generation of the Dictionary<Enum, Class> is not handled properly #3024

Open motuzko opened 4 years ago

motuzko commented 4 years ago

Test project attached.

NSwagIssue.zip

The missing Tools folder should contain the generator

image

The problem:

If the dictionary is Dictionary<TestEnum, Some_struct_ie_Decimal> the generated typescript is OK If the dictionary is Dictionary<TestEnum, Some_class> the generated typescript is OK in the class, but wrong in the interface (it adds I to the TestEnum):

export interface ITestClassWithDict2 { dictionary?: { [key in keyof typeof ITestEnum]?: ITestClass1; } | null; }

The typescript file is generated by the Client.Typescript project.

The nswag.json is there.

Please adivse.

RicoSuter commented 3 years ago

This is a bug in NJsonSchema and needs to be reproduced there in a unit test and fixed.

Shading29 commented 2 years ago

This is a bug in NJsonSchema and needs to be reproduced there in a unit test and fixed.

Will this fix? public Dictionary<SubscriptionProcessType, SubscriptionSettingsItem> SubscriptionSettings { get; set; }

generate ts file with wrong interface subscriptionSettings?: { [key in keyof typeof ISubscriptionProcessType]?: ISubscriptionSettingsItem; } | null;

But the class is generated normally subscriptionSettings?: { [key in keyof typeof SubscriptionProcessType]?: SubscriptionSettingsItem; } | null;