RicoSuter/NSwag

Global StringEnumConverter no longer respected

Open

#2,632 建立於 2020年1月17日

在 GitHub 查看
 (10 留言) (2 反應) (0 負責人)C# (1,189 fork)batch import
help wantedtype: bug

倉庫指標

Star
 (6,291 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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.

貢獻者指南