-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
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
.Net 6 TimeSpan is generated as schema in OpenAPI document but serialized as "time-span" formatted string #2505
Comments
I ran into the same issue. For now I'm using this work-around: builder.Services.AddSwaggerGen(options =>
{
options.MapType<TimeSpan>(() => new OpenApiSchema
{
Type = "string",
Example = new OpenApiString("00:00:00")
});
}); |
@domaindrivendev This is still a problem with .NET 7 and Swashbuckle.AspNetCore v6.5.0. Related issue: #1630 But it seems like there is also no standard for the format used by System.Text.Json. https://spec.openapis.org/registry/format/ contains |
It would be very nice if a part of addressing this issue would be providing the proper "format" and/or "pattern" field for the OpenApi. I am not sure if this is 100% correct, but I came up with this regex:
P.S. It limits the "days" part to only four digits, I guess it is really int.maxValue that is allowed, so a general case can support more of "days" digits |
Can you test if this works in DotSwashbuckle, there is custom mapping for TimeSpan to string // "date-span" |
This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made. |
Unstale |
This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made. |
Unstale |
I think this was fixed with #2804, or not? |
I don't know. I prefer people closing issues instead of bots defining "no activity, so the issue is no longer valid". |
This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made. |
Unstale. |
I'm using the latest .Net SDK 6.0.401 and Swashbuckle.AspNetCore 6.4.0
Application is generated using
dotnet new webapi
which includes Swashbuckle and uses System.Text.Json for serialization.The way
TimeSpan
properties are described in generated OpenAPI document does not match the way it is actually gets serialized by the application. In the OpenAPI documentTimeSpan
properties get this schema:"$ref": "#/components/schemas/TimeSpan"
but in runtime it is just serialized as a string in time-span format, for example:"00:01:02"
Maybe this breaking cnange in .Net 6.0.2 is a possible reason for this?
Minimal project demonstrating the problem is attached: SwashbuckleTimeSpan.zip
The text was updated successfully, but these errors were encountered: