Skip to content

Configure nswag to specify UTC when serializing DateTime#900

Merged
pmachapman merged 1 commit intomainfrom
nswag_specify_utc
Apr 13, 2026
Merged

Configure nswag to specify UTC when serializing DateTime#900
pmachapman merged 1 commit intomainfrom
nswag_specify_utc

Conversation

@pmachapman
Copy link
Copy Markdown
Collaborator

@pmachapman pmachapman commented Apr 8, 2026

Fixes #899


This change is Reviewable

@pmachapman pmachapman requested review from Enkidu93 and ddaspit April 8, 2026 23:59
@pmachapman pmachapman changed the title Configure nswag to specific UTC when serializing DateTIme Configure nswag to specify UTC when serializing DateTime Apr 8, 2026
@pmachapman pmachapman force-pushed the nswag_specify_utc branch 2 times, most recently from b945853 to efc4f18 Compare April 9, 2026 00:28
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.87%. Comparing base (68ca5c2) to head (0817c5b).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@ddaspit ddaspit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator Author

@pmachapman pmachapman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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.

Copy link
Copy Markdown
Contributor

@ddaspit ddaspit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@ddaspit reviewed all commit messages, made 2 comments, and resolved 1 discussion.
Reviewable status: :shipit: 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",, 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.

You're right. I missed that createdAfter and finishedAfter are DateTimeOffset instances and not DateTime instances.

Copy link
Copy Markdown
Collaborator

@Enkidu93 Enkidu93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@Enkidu93 reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on pmachapman).

@pmachapman pmachapman merged commit 714891c into main Apr 13, 2026
2 checks passed
@pmachapman pmachapman deleted the nswag_specify_utc branch April 13, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

created-after query parameter in the GetAllBuildsCreatedAfterAsync endpoint does not preserve time zone

4 participants