[Repo Assist] fix: use toParam in form content helpers for correct date/time serialization (+4 tests, 296→300)#395
Conversation
…ntent for correct date/time serialization (+4 tests, 296→300) Previously both functions used ToString() which gives locale-dependent output for DateTime/DateTimeOffset and incorrect formatting for DateOnly values. They now delegate to toParam, which uses ISO 8601 (O specifier) for DateTime and DateTimeOffset, and yyyy-MM-dd for DateOnly — the same formats used for query parameters. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates form-content serialization to use the existing toParam helper so DateTime/DateTimeOffset/DateOnly values are formatted consistently (ISO 8601 / round-trip) instead of relying on locale-dependent ToString() output.
Changes:
toMultipartFormDataContent: serialize non-stream values viatoParam, skipping values wheretoParamreturnsnull(e.g.,None)toFormUrlEncodedContent: serialize values viatoParam, excluding entries wheretoParamreturnsnull- Add 4 unit tests covering DateTime/DateTimeOffset formatting in both form content types
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/SwaggerProvider.Runtime/RuntimeHelpers.fs |
Routes form body field serialization through toParam to ensure consistent ISO formatting and option handling. |
tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs |
Adds regression tests for DateTime/DateTimeOffset formatting for both url-encoded and multipart form bodies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot review inline comments and address what is applicable |
Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/872fbd3c-11f7-4cfc-b551-87b698e37b4b Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Addressed the applicable inline review feedback in 77603d7 by tightening the new DateTime/DateTimeOffset tests to assert exact round-trip values ( |
|
@copilot should data in form content be url encoded? it is expected behavior? |
Yes— |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/0d67ee77-3aa2-4d0c-9a7f-907ce2203d48 Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/0d67ee77-3aa2-4d0c-9a7f-907ce2203d48 Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/0d67ee77-3aa2-4d0c-9a7f-907ce2203d48 Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
toFormUrlEncodedContentandtoMultipartFormDataContentpreviously calledx.ToString()/v.ToString()on field values, which gives locale-dependent output forDateTime/DateTimeOffsetand incorrect output forDateOnly. They now delegate totoParam, which applies the same ISO 8601 formatting already used for query parameters.Root cause
Both helpers were written before
toParamexisted as a dedicated serialization function. The TODO comment on the old code (// TODO: serialize? does not work with arrays probably) flagged the gap.Changes
RuntimeHelpers.fs:toMultipartFormDataContent: replacex.ToString()withtoParam x(skips null result — handles F#Noneoptions)toFormUrlEncodedContent: replaceSeq.map ... v.ToString()withSeq.choose ... toParam v(excludes entries wheretoParamreturns null)RuntimeHelpersTests.fs: 4 new tests verifying ISO 8601 formatting ofDateTimeandDateTimeOffsetvalues in both form content typesTest Status
✅
dotnet build— succeeded (0 errors)✅ Unit tests — 300 passed, 0 failed (1 skipped pre-existing)
✅
dotnet fantomas --check— no formatting issuesTrade-offs
toParamreturnsnullforNoneoptions; the updated code skips those entries rather than serializing"". This is consistent with howgetPropertyValuesalready filters outNonevalues before calling these helpers.toParamdelegation).