RicoSuter/NSwag

Global StringEnumConverter no longer respected

Open

#2,632 opened on Jan 17, 2020

View on GitHub
 (10 comments) (2 reactions) (0 assignees)C# (1,189 forks)batch import
help wantedtype: bug

Repository metrics

Stars
 (6,291 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

When applying the Newtonsoft.Json StringEnumConverter globally in an ASP.NET Core 3.1 application by doing the following:

services.AddControllers().AddNewtonsoftJson(options => options.SerializerSettings.Converters.Add(new StringEnumConverter()));

NSwag no longer generates the enum members as strings as it used to. If, however, the StringEnumConverter is specified directly on an enum like this:

[JsonConverter(typeof(StringEnumConverter))]
public enum MyEnum
...

It works as expected.

This issue was introduced at some point after version 13.1.5 (currently tested on 13.2.1).

I've created a small test application to reproduce the issue here: https://github.com/Sharparam/nswag-stringenum-test

Simply clone down the repo, build it in Release configuration, and run NSwag with the included nswag.json configuration.

Contributor guide