Repository navigation
[repo-assist] fix: formatObject correctly handles Option(T) elements in arrays - #475
Conversation
When a generated API type has a property of type `Option<DateOnly>[]`, `Option<TimeOnly>[]`, or `Option<string>[]`, the previous `appendFormattedArray` helper fell through to `obj.ToString()` for each element, producing locale-specific output like `Some(07/04/2025)` instead of ISO 8601. Fix: detect when the array element type is an F# option type (pre-computed `isOptionEl` flag) and unwrap each element using the cached tag reader and Value property (same caches used elsewhere in the file). The inner value is then formatted via `appendFormattedValue`, which correctly handles DateOnly/TimeOnly (ISO 8601), strings (quoted), and all other types. Add 6 new tests covering: - `array<Option<DateOnly>>` with Some and None elements - `array<Option<TimeOnly>>` with Some and None elements - `array<Option<string>>` with Some and None elements Total tests: 540 → 547. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates RuntimeHelpers.formatObject (used by generated provider types’ ToString() overrides) to correctly format arrays whose elements are Option<'T> (e.g., DateOnly option[], TimeOnly option[], string option[]) by unwrapping Some values and rendering None as null, avoiding locale-specific Some(...) output.
Changes:
- Add detection/handling for
array<Option<'T>>informatObject’s array formatting path to unwrap elements before formatting. - Add new unit tests covering arrays of optional
DateOnly,TimeOnly, andstringelements.
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 | Extends formatObject’s array formatting to unwrap Option<'T> elements and format inner values consistently. |
| tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs | Adds tests validating correct formatting for arrays of Option<DateOnly>, Option<TimeOnly>, and Option<string> elements. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot fix the build and review |
Fixed. CI failure was |
🤖 This PR was created by Repo Assist, an automated AI assistant.
Problem
When a generated API type has a property of type
Option<DateOnly>[],Option<TimeOnly>[], orOption<string>[](i.e., an array of optional values, not an optional array), theappendFormattedArrayhelper informatObjectfell through toobj.ToString()for each element. This produced locale-specific output likeSome(07/04/2025)instead of ISO 8601.This is a companion bug to the one fixed in #473, which handled
Option<DateOnly>andOption<TimeOnly>scalar properties. Arrays of option elements were not covered.Fix
In
appendFormattedArray, a newisOptionElflag is pre-computed before the element loop by checking whether the array's element type (elTy) is an F# option type. WhenisOptionElis true, each element is unwrapped using the existing cached tag reader +Valueproperty, then formatted viaappendFormattedValue(which handles ISO 8601 for DateOnly/TimeOnly, quoting for strings, andToString()for all others). None elements are rendered as"null".No new caches are introduced — this reuses
optionTagReaderCacheandoptionValueCachealready used throughout the file.Tests
6 new tests added (540 → 547 total):
array<Option<DateOnly>>all Some{Dates=[2025-01-01; 2025-12-31]}array<Option<DateOnly>>with None{Dates=[2025-07-04; null]}array<Option<TimeOnly>>all Some{Times=[14:30:00; 09:05:03.123]}array<Option<TimeOnly>>with None{Times=[null; 08:00:00]}array<Option<string>>mixed{Names=["hello"; null; "world"]}Test Status
✅ Build succeeded — 0 errors, 219 warnings (all pre-existing deprecation warnings).
✅ All 547 unit tests pass (1 pre-existing skip).
Add this agentic workflows to your repo
To install this agentic workflow, run