Skip to content

[repo-assist] fix: formatObject correctly handles Option(T) elements in arrays - #475

Merged
sergey-tihon merged 5 commits into
masterfrom
repo-assist/fix-formatobject-option-array-20260725-bffe35f82e81e0bd
Jul 25, 2026
Merged

sergey-tihon merged 5 commits into
masterfrom
repo-assist/fix-formatobject-option-array-20260725-bffe35f82e81e0bd

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 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>[], or Option<string>[] (i.e., an array of optional values, not an optional array), the appendFormattedArray helper in formatObject fell through to obj.ToString() for each element. This produced locale-specific output like Some(07/04/2025) instead of ISO 8601.

This is a companion bug to the one fixed in #473, which handled Option<DateOnly> and Option<TimeOnly> scalar properties. Arrays of option elements were not covered.

Fix

In appendFormattedArray, a new isOptionEl flag is pre-computed before the element loop by checking whether the array's element type (elTy) is an F# option type. When isOptionEl is true, each element is unwrapped using the existing cached tag reader + Value property, then formatted via appendFormattedValue (which handles ISO 8601 for DateOnly/TimeOnly, quoting for strings, and ToString() for all others). None elements are rendered as "null".

No new caches are introduced — this reuses optionTagReaderCache and optionValueCache already used throughout the file.

Tests

6 new tests added (540 → 547 total):

Test Expected
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).

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@e15e57b40918dbca11b350c55d02ab61934afa75

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>
@sergey-tihon
sergey-tihon marked this pull request as ready for review July 25, 2026 05:32
Copilot AI review requested due to automatic review settings July 25, 2026 05:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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>> in formatObject’s array formatting path to unwrap elements before formatting.
  • Add new unit tests covering arrays of optional DateOnly, TimeOnly, and string elements.

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.

Comment thread src/SwaggerProvider.Runtime/RuntimeHelpers.fs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sergey-tihon

Copy link
Copy Markdown
Member

@copilot fix the build and review

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

@copilot fix the build and review

Fixed. CI failure was FS0039 in RuntimeHelpers.fs (appendFormattedArray not defined); I made appendFormattedArray recursive in commit f686142 and validated with dotnet build tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj -c Release + dotnet tests/SwaggerProvider.Tests/bin/Release/net10.0/SwaggerProvider.Tests.dll (547 passed, 1 skipped). I also ran final PR validation (Code Review + CodeQL).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/SwaggerProvider.Runtime/RuntimeHelpers.fs Outdated
@sergey-tihon
sergey-tihon merged commit b9823f2 into master Jul 25, 2026
2 checks passed
@sergey-tihon
sergey-tihon deleted the repo-assist/fix-formatobject-option-array-20260725-bffe35f82e81e0bd branch July 25, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants