Configure nswag to specify UTC when serializing DateTime#900
Conversation
b945853 to
efc4f18
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #900 +/- ##
=======================================
Coverage 67.87% 67.87%
=======================================
Files 386 386
Lines 21256 21256
Branches 2749 2749
=======================================
Hits 14427 14427
Misses 5844 5844
Partials 985 985 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ddaspit
left a comment
There was a problem hiding this comment.
@ddaspit reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on Enkidu93 and pmachapman).
src/Serval/src/Serval.ApiServer/nswag.json line 49 at r1 (raw file):
"contractsNamespace": null, "contractsOutputFilePath": null, "parameterDateTimeFormat": "u",
My concern with this approach is that it will only work properly if the DateTime is already in UTC time. To make this robust, we would need to convert the DateTime to UTC before serializing using the u format. Is there any way to perform the conversion in Serval.Client? DateTimeOffset does perform the conversion automatically, so maybe we should use that instead.
efc4f18 to
1ffad01
Compare
pmachapman
left a comment
There was a problem hiding this comment.
@pmachapman made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on ddaspit and Enkidu93).
src/Serval/src/Serval.ApiServer/nswag.json line 49 at r1 (raw file):
Previously, ddaspit (Damien Daspit) wrote…
My concern with this approach is that it will only work properly if the
DateTimeis already in UTC time. To make this robust, we would need to convert theDateTimeto UTC before serializing using theuformat. Is there any way to perform the conversion inServal.Client?DateTimeOffsetdoes perform the conversion automatically, so maybe we should use that instead.
Based on the configuration below, "dateType": "System.DateTimeOffset",, in Client.g.cs, a DateTimeOffset is passed to GetAllBuildsCreatedAfterAsync and GetNextFinishedBuildAsync, so .ToString("u") will automatically convert from whatever timezone is specified to UTC, so from what I understand it is already converting?
If you want an explicit conversion in BuildService, I can update IBuildService to accept DateTimeOffset, which won't change Client.g.cs, as it already accepts DateTimeOffset.
1ffad01 to
0817c5b
Compare
ddaspit
left a comment
There was a problem hiding this comment.
@ddaspit reviewed all commit messages, made 2 comments, and resolved 1 discussion.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on Enkidu93).
src/Serval/src/Serval.ApiServer/nswag.json line 49 at r1 (raw file):
Previously, pmachapman (Peter Chapman) wrote…
Based on the configuration below,
"dateType": "System.DateTimeOffset",, inClient.g.cs, aDateTimeOffsetis passed toGetAllBuildsCreatedAfterAsyncandGetNextFinishedBuildAsync, so.ToString("u")will automatically convert from whatever timezone is specified to UTC, so from what I understand it is already converting?If you want an explicit conversion in
BuildService, I can updateIBuildServiceto acceptDateTimeOffset, which won't changeClient.g.cs, as it already acceptsDateTimeOffset.
You're right. I missed that createdAfter and finishedAfter are DateTimeOffset instances and not DateTime instances.
Enkidu93
left a comment
There was a problem hiding this comment.
@Enkidu93 reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on pmachapman).
Fixes #899
This change is