fix: wrap optional scalar reference types in Option<T> (#122)#357
Conversation
…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>
|
@copilot merge develop into this branch |
…ue-122-wrap-nullable-strings-362a357b9d702fbf # Conflicts: # tests/SwaggerProvider.Tests/v3/Schema.TestHelpers.fs # tests/SwaggerProvider.Tests/v3/Schema.TypeMappingTests.fs Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
There's no |
|
/repo-assist i don't want add WrapNullableStrings static parameters. i want to have the beharior of WrapNullableStrings=true by defaiult |
|
✗ Repo Assist encountered failed, see workflow run. |
|
@copilot i don't want add WrapNullableStrings static parameters. i want to have the beharior of WrapNullableStrings=true by defaiult |
…avior (remove WrapNullableStrings param) Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/345881f5-ff34-40a2-aeba-703b53cb2dbc Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Done in commit |
There was a problem hiding this comment.
Pull request overview
This PR aims to address #122 by allowing nullable/optional OpenAPI string properties to be represented as Option<string> in generated client types, aligning string behavior with existing optional value-type wrapping.
Changes:
- Updates v3
DefinitionCompilerto wrap non-requiredstringtypes inOption<string>. - Updates v3 mapping tests to expect
Option<string>for non-required strings (including inPreferNullablemode). - Updates the v2-compat compilation test (via v3 pipeline) to expect
Option<string>for an optional string property.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fs |
Adds unconditional wrapping of non-required string into Option<string>. |
src/SwaggerProvider.DesignTime/Provider.OpenApiClient.fs |
No functional change shown in diff; still constructs DefinitionCompiler without a WrapNullableStrings toggle. |
tests/SwaggerProvider.Tests/v3/Schema.TypeMappingTests.fs |
Changes expectations so optional strings map to Option<string>, including under PreferNullable. |
tests/SwaggerProvider.Tests/v3/Schema.V2SchemaCompilationTests.fs |
Changes v2-compat expectation so an optional string property becomes string option. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot why don't you use Option.ofString if runtime to avoid Some(null) ? |
…option setters Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/4f7cea4d-4b04-4690-8f42-618b300354b1 Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Added in commit |
…behavior tests Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/7e0210bf-5236-4b01-a81f-850ea0d1cc88 Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
…e v2 provider Extend Option<T> wrapping from string-only to all scalar reference types (string, IO.Stream, byte[*]) in the v3 DefinitionCompiler. Collection types (arrays, maps) and provided object types remain unwrapped. Strengthen the Obsolete attribute on SwaggerClientProvider to an explicit deprecation notice directing users to OpenApiClientProvider. Add byte-array Option deserialization tests and extend type mapping tests to cover Stream and byte[] wrapping.
…ullable=true; add tests Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/317c7465-cd4a-4896-9c89-808d8fc38a3f Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
There's no
Done in commit
Verified in commit |
|
@copilot fix build |
…am/byte[] fields Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/099ce0a4-f3ab-40d6-b12b-038f654293f3 Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Fixed in commit
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Closes #122
Root Cause
DefinitionCompilerwraps non-required value types (e.g.,bool option,int option) inOption<T>, but skips reference types entirely because they're already nullable by the CLR. This means optional string,byte[], andStreamfields come through as plain unwrapped types even though the F# type system should reflect the optional/absent distinction.Fix
Extend the
Option<T>wrapping in the v3DefinitionCompilerfrom string-only to all scalar reference types:string,IO.Stream, andbyte[*]. Collection types (arrays, maps) and provided object types remain unwrapped — they naturally express absence via null/empty.This is a breaking change for consumers who previously received bare
string/Stream/byte[]for optional fields; they will now receiveOption<T>instead.The v2
SwaggerClientProvideris not updated — itsObsoleteattribute is strengthened to an explicit deprecation notice directing users toOpenApiClientProvider.Changes
src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fsstring,IO.Stream, andbyte[*]inOption<T>when non-requiredsrc/SwaggerProvider.DesignTime/Provider.SwaggerClient.fsObsoleteattribute to explicit deprecation noticetests/SwaggerProvider.Tests/v3/Schema.TypeMappingTests.fsOption<byte[*]>; addoptional binary maps to Option<Stream>testtests/SwaggerProvider.Tests/RuntimeHelpersTests.fsByteArrayOptionClass+ 3 deserialization tests forbyte array option; rename module toOptionDeserializationTestsTest Status
✅ Build: succeeded (0 errors)
✅ Unit tests: 337 passed, 0 failed, 2 skipped
✅ Format check:
fantomasapplied and verified clean