Skip to content

[SEL-138] Match FSharp.SystemTextJson for per-type options, option elements and skippable option fields - #3

Merged
lukaszkrzywizna merged 3 commits into
mainfrom
fix-option-overrides
Nov 24, 2026
Merged

lukaszkrzywizna merged 3 commits into
mainfrom
fix-option-overrides

Conversation

@lukaszkrzywizna

@lukaszkrzywizna lukaszkrzywizna commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

The OpenAPI schema must describe exactly the JSON FSharp.SystemTextJson writes. This fixes three gaps where it did not; each new test asserts the serialized JSON next to the schema and fails on the previous code.

  1. Per-type options (FsOptions.getEffectiveFsOptions) now follow FSharp.SystemTextJson's overrideOptions: WithOverrides first (type or generic definition), [<JsonFSharpConverter>] only with AllowOverride, and the global union encoding inherited when the per-type options do not set it. Before, the attribute was used as-is (also without AllowOverride) and WithOverrides was ignored. Example: [<JsonFSharpConverter(UnionTagName = "type")>] with internal-tag, named-field global options wrote {"type":"Circle","radius":1}, but the schema described {"type":"Circle","Fields":[...]}.
  2. option/voption in tuple elements, positional union fields and unwrapped single-field cases allow null ([null,1] was rejected). UnwrapOption for an option field now comes from the options for option<_>/voption<_>, so WithOverrides on option<_> applies too. Tuple and positional items use anyOf: a value can match more than one element type (["PosPair","PosPair",2], [null,null]), which oneOf rejected.
  3. SkippableOptionFields decides whether an option field in a record or named union field is required; an unwrapped record case uses the record's own options.

Breaking change (before 1.0.0): TupleSchemaTransformer takes JsonFSharpOptions again. Users who relied on the old advice not to use WithOverrides can now use it. Not supported and documented: WithOverrideMembers, MapFormat.

Monorepo check on a locally packed package (SelectView, all 7 OpenAPI snapshots regenerated): one change, the Invoice Search tuple of InvoiceViewColumn items goes from oneOf to anyOf; openapi-typescript renders both as the same union.

Review: Sol xhigh and Opus high panel; Act-on findings (oneOf regression, unwrapped record options, per-type UnwrapOption) fixed in c6117bb; fresh Opus high fix-round review with no Act-on items; its notes applied. Ticket: SEL-138.

🤖 Generated with Claude Code


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

lukaszkrzywizna and others added 3 commits November 24, 2026 12:00
…ements and skippable option fields

- Per-type options: apply WithOverrides first, read [<JsonFSharpConverter>]
  only with AllowOverride, and inherit the global union encoding when the
  per-type options do not set it (port of FSharp.SystemTextJson's
  overrideOptions).
- option and voption tuple elements, positional union fields and unwrapped
  single-field cases allow null.
- Record and named union fields follow SkippableOptionFields when deciding
  whether an option field is required.

Each new test asserts the serialized JSON next to the schema and failed
before the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… unwrap, record options in unwrapped cases

- Tuple and positional case items use anyOf: a value can match more than
  one element type (a field equal to the case tag, two option elements
  that are null), which oneOf rejected.
- An option or voption field decides UnwrapOption from the options for
  option<_> or voption<_>, so WithOverrides on option<_> applies to tuple
  elements and positional fields too.
- An unwrapped record case uses the record's own options, layered on the
  union's, like FSharp.SystemTextJson.
- Tests check the specific element schema; each new one fails on the
  previous commit. Docs name WithOverrideMembers and MapFormat as not
  supported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… options test, drop dead helpers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lukaszkrzywizna
lukaszkrzywizna merged commit 043bc44 into main Nov 24, 2026
3 checks passed
@lukaszkrzywizna
lukaszkrzywizna deleted the fix-option-overrides branch November 24, 2026 11:13
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.

1 participant