1

When i try to convert the below enum property, it doesn't change as expected.

I used the nswag to generate the code in typescript from my EF core API, the enum based class doesn't convert as expected when using [DisplayName] or [Description] DataAnnotation.

Property:

[Description("26\"")] TwentySix = 1,

Output:

export enum Sizes {
    TwentySix = 1, 
}

Expectation:

export enum Sizes {
   26"= 1,
}

Added the below code in the "ConfigureServices",

services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver());

Or

services.AddMvc().AddJsonOptions(options => options.SerializerSettings.Converters.Add(new StringEnumConverter()));

In nswag.json,

Under "codeGenerators" i have the below property,

 "enumNameGeneratorType": null,

My other service method and classes are working fine. The "Description" attribute didn't work, tried "DisplayName" too.

What should i change here?

A Coder
  • 3,039
  • 7
  • 58
  • 129
  • 1) You would probably need your own custom converter that acknowledges the `DescriptionAttribute` 2) You are duplicating a lot of code in the `ConfigureServices` – Nkosi Jun 21 '19 at 18:26
  • Do you literally mean that it renders the syntactically invalid code above? If so, it's likely to do with the `\"` In the description. I'm not sure why you would have that character in your description but and swag probably isn't handling it because it's a weird edge case they didn't think of. – Aluan Haddad Jun 25 '19 at 04:07
  • Yeah almost, i was expecting is there anyway that i can bring the expected output. – A Coder Jun 26 '19 at 06:52

0 Answers0