Swashbuckle.AspNetCore
Swashbuckle.AspNetCore copied to clipboard
Newtonsoft UnixDateTimeConverter is not respected
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 DateTime
s 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
.