[repo-assist] fix: formatObject correctly handles Option(DateOnly) and Option(TimeOnly) properties#473
Merged
sergey-tihon merged 3 commits intoJul 18, 2026
Conversation
…nly> properties Previously, Option<DateOnly> and Option<TimeOnly> properties fell through to obj.ToString(), producing locale-specific output like "Some(07/04/2025)" instead of the ISO 8601 value used by toParam and the rest of the serialization layer. This commit: - Extracts a private appendFormattedValue helper (string quoted, DateOnly/TimeOnly ISO 8601, other types via ToString) used by both the scalar and array branches. - Adds an Option<T> unwrapping arm in formatObject: Some(x) formats x via appendFormattedValue; None appends "null". - In the array branch, uses the pre-computed elTy directly instead of calling x.GetType() on each element when isDateOnly/isTimeOnly is already known. - Adds 9 new tests covering Option<DateOnly>, Option<TimeOnly>, Option<string>, and Option<int> — both Some and None cases (540 tests total, was 525). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the runtime formatObject helper (used by generated provider types’ ToString() overrides) to format Option<DateOnly> / Option<TimeOnly> values using ISO-8601-style output instead of culture-dependent Option<T>.ToString() output.
Changes:
- Extracts a private
appendFormattedValuehelper to centralize scalar formatting (string quoting,DateOnly/TimeOnlyformatting). - Adds
Option<T>unwrapping informatObjectsoSome(x)formatsxandNoneprintsnull(using cached reflection helpers). - Adds new unit tests intended to cover option formatting cases for
DateOnly,TimeOnly,string, andint.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/SwaggerProvider.Runtime/RuntimeHelpers.fs | Adds scalar formatting helper and an Option<T> formatting arm to formatObject. |
| tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs | Adds new FormatObjectTests cases for option values. |
Comments suppressed due to low confidence (1)
tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs:1299
toFormUrlEncodedContenttests are now insideFormatObjectTests(themodule ToFormUrlEncodedContentTests =header appears to have been removed). This changes the fully-qualified test names and makes filtering/running just the form-url-encoding tests harder, and is inconsistent with the rest of this file which groups tests by helper function in separate modules.
[<Fact>]
let ``toFormUrlEncodedContent encodes key-value pairs``() =
task {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
@copilot fix the build |
Contributor
Addressed in |
sergey-tihon
deleted the
repo-assist/fix-formatobject-option-dateonly-20260718-4dce593f97db4d19
branch
July 18, 2026 11:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
formatObjectis used by the generatedToString()override on provider types to produce a debug-friendly{Prop=value; ...}string. Previously,Option<DateOnly>andOption<TimeOnly>properties fell through toobj.ToString(), which produces locale-specific output likeSome(07/04/2025)instead of the ISO 8601 value that the rest of the serialization layer uses.Root cause
The
formatObjectfunction handledDateOnly/TimeOnlyscalars and arrays explicitly, but did not unwrap F#Option<T>before formatting.Option<DateOnly>.ToString()calls.NET's default box-then-print, givingSome(07/04/2025)in en-US locale or similar culture-dependent strings elsewhere.Fix
appendFormattedValuehelper (string → quoted,DateOnly/TimeOnly→ ISO 8601, other types →ToString()) used by both the scalar and array branches, eliminating the duplicated formatting logic.Option<T>unwrapping arm:Some(x)formatsxviaappendFormattedValue;Noneappends"null". Uses the existingoptionTagReaderCache/optionValueCacheinfrastructure, so there is zero extra reflection cost after the first call per type.elTydirectly instead of callingx.GetType()on each element whenisDateOnly/isTimeOnlyis already known (minor performance improvement — addresses Task 8).Trade-offs
Option<DateOnly>andOption<TimeOnly>cases are affected.Option<string>(produces"hello"instead ofSome("hello")) andOption<int>(produces42instead ofSome(42)), which are common in generated provider types.Test Status
9 new tests added in
FormatObjectTestscovering:Option<DateOnly>Some → ISO 8601, None →nullOption<TimeOnly>Some →HH:mm:ss.FFFFFFF, None →nullOption<string>Some → quoted, None →nullOption<int>Some → integer, None →nullAll 540 tests pass (was 525 before this run; previous runs added other tests). Fantomas format check passes.
Add this agentic workflows to your repo
To install this agentic workflow, run