cancel
Showing results for 
Search instead for 
Did you mean: 

Swagger codegen for enum with Data Annotations

Highlighted
Occasional Visitor

Swagger codegen for enum with Data Annotations

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?

Tags (3)
New Here?
Join us and watch the welcome video:
Watch the New Interview
APITestingMistake#2
Top Kudoed Authors