RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.67k stars 1.23k forks source link

DateOnly parameter in URL/querystring is serialized with time #3958

Open Shaddix opened 2 years ago

Shaddix commented 2 years ago

Currently if backend method contains a DateOnly query parameter, the generated code looks like that:

if (pickupDate !== undefined && pickupDate !== null)
      url_ += 'PickupDate=' + encodeURIComponent(pickupDate ? '' + pickupDate.toJSON() : '') + '&';

It actually serializes the value in ISO with time and timezone ('2022-04-02T00:00:00Z'). I guess it'd be preferable to have it serialized as date only ('2022-04-02'), especially because it's serialized like that when DateOnly parameter is in body of POST request.

If you agree that this is an issue, I could provide a pull request (actually, I already implemented and tested it as part of another project)

nilzen commented 1 year ago

I would love to see a PR for this @Shaddix - I hacked around this in the project I'm working on, but to be able to work with correctly typed objects everywhere would be awesome!

killergege commented 1 year ago

I'd also like this issue fixed, especially since ASP.NET 7 now supports natively DateOnly, I'd love to be able to remove my custom type converter (native converter throws a format error if the string has time).

Shaddix commented 1 year ago

Just to track it here as well, there's a PR: #4262 (submitted on Dec, 6, 2022).

I already used it in react-query-swagger (which is more for react-query, but could be used to generate plain clients as well).

Feoni4 commented 1 year ago

Hello, also faced an issue with DateOnly serialization in the Query parameter. Waiting for a fix to be merged!

robinjhector commented 1 year ago

Sorry to bump this, but could we get this fixed? Seems like a pretty weird inconsistency

dannykempkes commented 5 months ago

Bump. Any further news on this?

pinkfloydx33 commented 4 months ago

This is blocking us from switching over to DateOnly for some properties that really need to be just dates as aspnetcore rejects the value as the DateOnly.Parse method does not like the time component and I've found no way to opt out of this other than by using a string as the type which I'd prefer not doing