Skip to content

[Repo Assist] feat: add WrapNullableStrings static parameter to OpenApiClientProvider#357

Draft
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/fix-issue-122-wrap-nullable-strings-362a357b9d702fbf
Draft

[Repo Assist] feat: add WrapNullableStrings static parameter to OpenApiClientProvider#357
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/fix-issue-122-wrap-nullable-strings-362a357b9d702fbf

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 6, 2026

🤖 This PR was created by Repo Assist, an automated AI assistant.

Closes #122

Root Cause

DefinitionCompiler wraps non-required value types (e.g., bool option, int option) in Option<T>, but skips reference types entirely because they're already nullable by the CLR. This means nullable: true string fields come through as plain string even though the user might want the F# type system to reflect the optional/absent distinction.

Fix

Add a WrapNullableStrings static parameter (default false) to OpenApiClientProvider. When set to true, optional/nullable string fields are wrapped in Option<string>, consistent with how FSharp.Data.SqlClient maps varchar NULLstring option.

The default is false to preserve full backwards compatibility — existing users who read nullable strings as string are unaffected unless they opt in.

// opt-in: nullable strings become Option<string>
type Api = OpenApiClientProvider<"schema.yaml", WrapNullableStrings=true>

Changes

File Change
src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fs Add ?wrapNullableStrings: bool optional parameter; apply Option<string> wrapping when enabled
src/SwaggerProvider.DesignTime/Provider.OpenApiClient.fs Add WrapNullableStrings static parameter, thread it through to DefinitionCompiler, include in cache key
tests/SwaggerProvider.Tests/v3/Schema.TestHelpers.fs Add compilePropertyTypeWith helper that accepts provideNullable and wrapNullableStrings
tests/SwaggerProvider.Tests/v3/Schema.TypeMappingTests.fs Add 5 tests covering WrapNullableStrings=false (default), =true with optional string, =true with required string, =true with date-time, and =true with integer

Test Status

✅ Build: succeeded (0 errors, warnings are pre-existing)
✅ Unit tests: 268 passed, 0 failed, 2 skipped (same as baseline)
✅ New WrapNullableStrings tests: all 5 pass
✅ Format check: fantomas applied and re-verified clean

Integration/provider tests require a running Swashbuckle test server and were not run; the new parameter does not touch HTTP or serialization logic.

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

To install this agentic workflow, run

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

…er (closes #122)

When WrapNullableStrings=true, optional/nullable string fields are
wrapped as Option<string> instead of plain string, matching the
treatment of other optional value types (bool, int, float, etc.).

Defaults to false to preserve backwards compatibility.

- Add WrapNullableStrings static parameter to DefinitionCompiler (optional arg)
- Pass parameter through Provider.OpenApiClient.fs to DefinitionCompiler
- Include WrapNullableStrings in the type-generation cache key
- Add compilePropertyTypeWith helper in test helpers
- Add 5 tests covering WrapNullableStrings=false/true/required scenarios

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

String field cannot be optional.

0 participants