Swashbuckle.AspNetCore icon indicating copy to clipboard operation
Swashbuckle.AspNetCore copied to clipboard

Newtonsoft UnixDateTimeConverter is not respected

Open lus opened this issue 2 years ago • 3 comments

I set up SwaggerGen with Newtonsoft support like this:

builder.Services.AddSwaggerGen(options =>
{
    string filename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
    options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, filename));
});
builder.Services.AddSwaggerGenNewtonsoftSupport();

Newtonsoft is configured like this:

builder.Services.AddControllers().AddNewtonsoftJson(options =>
{
    options.SerializerSettings.Converters.Add(new StringEnumConverter(typeof(CamelCaseNamingStrategy)));
    options.SerializerSettings.Converters.Add(new UnixDateTimeConverter());
    options.SerializerSettings.ContractResolver = new DefaultContractResolver
    {
        NamingStrategy = new SnakeCaseNamingStrategy(),
    };
});

In the example response I see that both the SnakeCaseNamingStrategy and my custom StringEnumConverter are correctly applied, but the UnixDateTimeConverter seems to be ignored as DateTimes still get represented as strings. Am I missing something or is this a bug?

I am using Swashbuckle.AspNetCore and Swashbuckle.AspNetCore.Newtonsoft version 6.5.0.

lus avatar Feb 09 '23 10:02 lus