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

Enum properties missing from example when StringEnumConverter is used in ASP.net core 3 #2449

Open ghost opened 4 years ago

ghost commented 4 years ago

When I set the StringEnumConverter setting (globally or on the enum itself via an attribute) the enum field will be missing from the example (for a method that takes a type with the enum as a property as argument) in the Swagger UI. It's visible in the schema just fine (with textual values). When the StringEnumConverter is removed, the example contains the enum field again (with numeric values).

I have NSwag.AspNetCore Version="13.1.2 and .net core 3 final. This used to work with asp.net core 2.

RicoSuter commented 4 years ago

Are you still using the Newtonsoft.Json serializer in ASP.NET Core 3.0?

ghost commented 4 years ago

Yes. I thought that's still required if you want some control over how the JSON is serialised. Or is there a way to get the Microsoft JSON serialiser to serialise enums as string?

ghost commented 4 years ago

Ok, so the problem occurs if you apply the [Required] attribute to the property. Without it it shows up in the example with a textual value as it should. Granted, the required attribute doesn't really work for value types anyway, but it's still odd behavior.