NSwag
NSwag copied to clipboard
DateOnly parameter in URL/querystring is serialized with time
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)
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!
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).
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).
Hello, also faced an issue with DateOnly serialization in the Query parameter. Waiting for a fix to be merged!
Sorry to bump this, but could we get this fixed? Seems like a pretty weird inconsistency
Bump. Any further news on this?
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