I have a class that is exposed through Swashbuckle that looks something like this:
public class Person
{
[JsonProperty("dateOfBirth")]
[JsonConverter(typeof(DateFormatConverter))]
public System.DateTime? DateOfBirth { get; set; }
}
internal class DateFormatConverter : Newtonsoft.Json.Converters.IsoDateTimeConverter
{
public DateFormatConverter()
{
DateTimeFormat = "yyyy-MM-dd";
}
}
(The class was generated by NSwag-studio)
When I use app.UseSwagger();
to generate a Swagger contract with Swashbuckle, the result looks like this:
"Person": {
"dateOfBirth": {
"format": "date-time",
"type": "string"
}
}
}
I would like to configure Swashbuckle to recognize my DateFormatConverter
class and treat the format accordingly.
I tried options.SchemaFilter<DateFormatSchemaFilter>()
in my Startup
class, but the filter doesn't have the context of the property, so unless I want all DateTime objects to be date
, this isn't a viable option.