Skip to content

[SEL-138] Allow null for voption record fields - #2

Merged
lukaszkrzywizna merged 3 commits into
mainfrom
sel-138-voption-null
Nov 24, 2026
Merged

lukaszkrzywizna merged 3 commits into
mainfrom
sel-138-voption-null

Conversation

@lukaszkrzywizna

@lukaszkrzywizna lukaszkrzywizna commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

With UnwrapOption (the default), a record field of type 'T voption was described as the inner schema only. FSharp.SystemTextJson writes ValueNone as null, so the JSON could hold a null that the schema did not allow.

Runtime proof with the test options:

Value JSON
{ MaybeV = ValueNone } {"maybeV":null}
{ MaybeV = ValueSome "x" } {"maybeV":"x"}
top-level ValueNone null

Change:

  • Record and union transformers share one option-or-voption pattern, so a voption record or union field gets the inner schema plus null, like option. A top-level value keeps the inner schema only (unchanged, same as top-level option). The Option transformer's unwrapped voption branch now takes the option path too.
  • A nested option field is encoded with the global options even when the parent overrides UnwrapOption with [<JsonFSharpConverter>] (runtime: global false + parent true writes {"MaybeV":{"Case":"ValueNone"},"Maybe":null}). The record and union transformers now read the field encoding from the global options. For option fields this was already wrong on main in the same way.
  • Option tests run the transformer set that AddOpenApiForSystemTextJson registers and assert the serialized JSON next to the schema. The record-with-voption test locked in the wrong shape before. New cases: voption union field, per-type override.
  • README and the agent skill describe the new shape. Version 0.1.1.

Release plan: v0.1.1-preview.1 first, verified against the SelectView monorepo OpenAPI snapshots, then v0.1.1 on the same commit.

Review of record: SelectView Review contract panel, non-mechanical tier. Round 1: Sol xhigh + Opus high (two Act-on items, both fixed above). Fix round: fresh Opus high on 08a4274..ca32cc3, no Act-on items.

Non-blocking follow-ups (reproduced, unchanged from main):

  • Tuple elements and positional union fields of type option/voption get no null: { T: int * string voption } with (1, ValueNone) writes {"T":[1,null]}, but the item schema has no null.
  • A union-level [<JsonFSharpConverter>] override replaces all options in the schema, while the runtime does not apply it that way, so the union shape can differ from the JSON.

🤖 Generated with Claude Code

lukaszkrzywizna and others added 3 commits November 24, 2026 11:14
FSharp.SystemTextJson writes ValueNone in a record field as null, but the
schema showed only the inner type. Unwrapped voption now takes the same
path as unwrapped option: record fields get the inner schema plus null,
top-level values keep the inner schema only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed transformers

The record and union transformers build field schemas themselves and only
matched option, so voption fields still lacked null with the transformer
set that AddOpenApiForSystemTextJson registers. Both now share one
option-or-voption pattern. The option tests run the shipped set and
assert the serialized JSON next to the schema.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… parent's override

FSharp.SystemTextJson encodes a nested option or voption field with the
global options, even when the parent record or union overrides
UnwrapOption with [<JsonFSharpConverter>]. The record and union
transformers used the parent's options, so they described a wrapped
ValueNone as string or null.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lukaszkrzywizna
lukaszkrzywizna merged commit ac0380a into main Nov 24, 2026
2 checks passed
@lukaszkrzywizna
lukaszkrzywizna deleted the sel-138-voption-null branch November 24, 2026 10:33
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