I need some help understanding why swagger is showing an extra field as part of the input to a POST method using ASP.NET Core.
I have a constructor endpoint like this:
public async Task<IActionResult> AddHours([FromBody] List<HoursForDay> hoursList)
The HoursForDay record looks like this:
public readonly record struct HoursForDay(DateOnly Date, int Hours);
The .NET Core DateOnly struct has 2 ctors that looks like this (https://learn.microsoft.com/en-us/dotnet/api/system.dateonly?view=net-6.0):
DateOnly(Int32, Int32, Int32)
DateOnly(Int32, Int32, Int32, Calendar)
But my swagger page shows this input schema:
[
{
"date": {
"year": 0,
"month": 0,
"day": 0,
"dayOfWeek": "Sunday"
},
"hours": 0
}
]
Can someone help me understand why the "dayOfWeek" attribute is being shown as part of the input?
And how to get rid of it? I'm aware of the option to create a custom type that has just year, month, day attributes, I'm looking for other options.
UPDATE
HoursForDay.cs
DateOnlySchemaFilter.CS
PREVIOUS
Reason
You should use
[JsonIgnore]attributes to avoid it.Test Code and Result