Skip to content
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

DateOnly and TimeOnly are displayed as complex objects in open-api schemas rather simple string #37045

Closed
rafikiassumani-msft opened this issue Sep 28, 2021 · 6 comments
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-openapi Priority:2 Work that is important, but not critical for the release

Comments

@rafikiassumani-msft
Copy link
Contributor

Describe the bug

DateOnly and TimeOnly are being displayed as complex objects in open api schemas for Minimal API endpoints rather than being treated as simple strings. It will make sense for open api to treat them as string -$date-only and string -$time-only

app.MapGet("/events", (DateOnly dateOnly, TimeOnly timeonly) => $" date and time values ... ")

Exceptions (if any)

  ### Further technical details
  .NET SDK (reflecting any global.json):
   Version:   6.0.100-rc.2.21465.13
   Commit:    0d1cdfa6a0
  
  Runtime Environment:
   OS Name:     Windows
   OS Version:  10.0.19043
   OS Platform: Windows
   RID:         win10-x64
   Base Path:   C:\Program Files\dotnet\sdk\6.0.100-rc.2.21465.13\
@rafikiassumani-msft rafikiassumani-msft added feature-openapi area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Sep 28, 2021
@rafikiassumani-msft rafikiassumani-msft added this to the .NET 7 Planning milestone Sep 28, 2021
@rafikiassumani-msft
Copy link
Contributor Author

This may need a change in Swashbuckle and N-Swag for these new primitives.

@rafikiassumani-msft rafikiassumani-msft added Cost:S Priority:2 Work that is important, but not critical for the release labels Jan 25, 2022
@captainsafia
Copy link
Member

Looked into this briefly. Draft 07 of the JSON schema adds support for the date and time formats on strings (ref). Until that is officially incorporated into the spec, it probably makes sense to keep this as an object.

@DamianEdwards
Copy link
Member

Looks like this doesn't happen now in .NET 7, but it's still not perfect. It's now projected as a string (good!) but with the "date-time" format (bad!). Seems Swagger does actually support "date" as a format now so we should get Swashbuckle updated to map DateOnly to "string" formatted as "date". Swashbuckle has an issue filed for this already.

@DamianEdwards DamianEdwards removed their assignment Jun 14, 2022
@DamianEdwards
Copy link
Member

DamianEdwards commented Aug 6, 2022

Workaround by adding a type mapping to Swashbuckle until they fix their defaults:

builder.Services.AddSwaggerGen(
    c.MapType<DateOnly>(() => new OpenApiSchema
    {
        Type = "string",
        Format = "date"
    });
);

@ghost
Copy link

ghost commented Oct 11, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@captainsafia
Copy link
Member

@rafikiassumani-msft I think we should close this in favor of domaindrivendev/Swashbuckle.AspNetCore#2319. I already have a PR out to fix it at domaindrivendev/Swashbuckle.AspNetCore#2480

@ghost ghost locked as resolved and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-openapi Priority:2 Work that is important, but not critical for the release
Projects
None yet
Development

No branches or pull requests

3 participants