We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CamelCase NamingStrategy for enums not working with System.Text.Json NSwag version: 13.15.7
To reproduce:
using System.Text.Json; using System.Text.Json.Serialization; using Microsoft.AspNetCore.Mvc; using NswagApi; var builder = WebApplication.CreateBuilder(args); builder.Services.AddEndpointsApiExplorer() .AddOpenApiDocument(settings => settings.Title = "Title") .Configure<JsonOptions>(options => { options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)); }); var app = builder.Build(); app.MapGet("/", () => new SampleDto { Enum = SampleEnum.Foo }); app.UseOpenApi(); app.Run();
Generated json:
"SampleEnum": { "type": "string", "description": "", "x-enumNames": [ "Foo", "Bar" ], "enum": [ "Foo", "Bar" ] }
Looks like it's somehow related to this code in SystemTextJsonUtilities.cs:
public static JsonSerializerSettings ConvertJsonOptionsToNewtonsoftSettings(dynamic serializerOptions) { var settings = new JsonSerializerSettings { ContractResolver = new SystemTextJsonContractResolver(serializerOptions) }; if (((IEnumerable)serializerOptions.Converters).OfType<object>().Any(c => c.GetType().IsAssignableToTypeName("System.Text.Json.Serialization.JsonStringEnumConverter", TypeNameStyle.FullName))) { settings.Converters.Add(new StringEnumConverter()); } return settings; }
It simply creates StringEnumConverter without naming strategy.
The text was updated successfully, but these errors were encountered:
#1491 CamelCase NamingStrategy for enums not working with System.Text…
e082783
….Json (#1492) * fix: system.text.json enum naming policy * Update SystemTextJsonUtilities.cs Co-authored-by: Rico Suter <mail@rsuter.com>
No branches or pull requests
CamelCase NamingStrategy for enums not working with System.Text.Json
NSwag version: 13.15.7
To reproduce:
Generated json:
Looks like it's somehow related to this code in SystemTextJsonUtilities.cs:
It simply creates StringEnumConverter without naming strategy.
The text was updated successfully, but these errors were encountered: