NSwag icon indicating copy to clipboard operation
NSwag copied to clipboard

DateOnly parameter in URL/querystring is serialized with time

Open Shaddix opened this issue 2 years ago • 7 comments

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)

Shaddix avatar Apr 02 '22 15:04 Shaddix

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!

nilzen avatar Dec 06 '22 12:12 nilzen

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).

killergege avatar Feb 02 '23 16:02 killergege

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).

Shaddix avatar Feb 03 '23 02:02 Shaddix

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

Feoni4 avatar Mar 01 '23 16:03 Feoni4

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

robinjhector avatar Mar 14 '23 10:03 robinjhector

Bump. Any further news on this?

dannykempkes avatar Mar 18 '24 20:03 dannykempkes

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

pinkfloydx33 avatar Apr 13 '24 19:04 pinkfloydx33