Skip to content

Commit dec1bdd

Browse files
github-actions[bot]CopilotCopilotsergey-tihon
authored
[Repo Assist] test: extend DateOnly/TimeOnly type-mapping coverage (+7 tests, 317→324) (#397)
* test: extend DateOnly/TimeOnly type-mapping coverage (+7 tests, 317→324) Add the tests that were missing after PRs #393 and #394 landed: * required date → DateOnly when useDateOnly=true * optional date → Option<DateOnly> when useDateOnly=true * optional time → Option<TimeOnly> when useDateOnly=true * PreferNullable+useDateOnly: optional DateOnly → Nullable<DateOnly> * PreferNullable+useDateOnly: required DateOnly stays unwrapped * PreferNullable+useDateOnly: optional TimeOnly → Nullable<TimeOnly> * PreferNullable+useDateOnly: required TimeOnly stays unwrapped Also expose compilePropertyTypeWithNullableAndDateOnly helper in Schema.TestHelpers for the PreferNullable×useDateOnly combination. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger checks * test: clarify useDateOnly=false expectation in date format mapping test Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/564a5cd8-95fa-4822-8a43-a8e1132ed123 Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
1 parent bdebedb commit dec1bdd

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

tests/SwaggerProvider.Tests/Schema.TestHelpers.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,7 @@ let compilePropertyTypeWith (provideNullable: bool) (propYaml: string) (required
101101
/// Compile a minimal v3 schema where date/time formats map to DateOnly/TimeOnly types.
102102
let compilePropertyTypeWithDateOnly (propYaml: string) (required: bool) : Type =
103103
compilePropertyTypeWithOptions false true propYaml required
104+
105+
/// Compile a minimal v3 schema with both PreferNullable and useDateOnly options enabled.
106+
let compilePropertyTypeWithNullableAndDateOnly (propYaml: string) (required: bool) : Type =
107+
compilePropertyTypeWithOptions true true propYaml required

tests/SwaggerProvider.Tests/Schema.TypeMappingTests.fs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,18 @@ let ``required string date-time format maps to DateTimeOffset``() =
5454
ty |> shouldEqual typeof<DateTimeOffset>
5555

5656
[<Fact>]
57-
let ``required string date format maps to DateTimeOffset``() =
57+
let ``required string date format maps to DateTimeOffset when useDateOnly is false``() =
5858
let ty = compilePropertyType " type: string\n format: date\n" true
5959

6060
ty |> shouldEqual typeof<DateTimeOffset>
6161

62+
[<Fact>]
63+
let ``required string date format maps to DateOnly when useDateOnly is true``() =
64+
let ty =
65+
compilePropertyTypeWithDateOnly " type: string\n format: date\n" true
66+
67+
ty |> shouldEqual typeof<DateOnly>
68+
6269
[<Fact>]
6370
let ``required string time format falls back to string when useDateOnly is false``() =
6471
// The test helper compiles with useDateOnly=false, so TimeOnly is not used
@@ -136,6 +143,22 @@ let ``optional DateTimeOffset maps to Option<DateTimeOffset>``() =
136143
ty
137144
|> shouldEqual(typedefof<Option<_>>.MakeGenericType(typeof<DateTimeOffset>))
138145

146+
[<Fact>]
147+
let ``optional DateOnly maps to Option<DateOnly> when useDateOnly is true``() =
148+
let ty =
149+
compilePropertyTypeWithDateOnly " type: string\n format: date\n" false
150+
151+
ty
152+
|> shouldEqual(typedefof<Option<_>>.MakeGenericType(typeof<DateOnly>))
153+
154+
[<Fact>]
155+
let ``optional TimeOnly maps to Option<TimeOnly> when useDateOnly is true``() =
156+
let ty =
157+
compilePropertyTypeWithDateOnly " type: string\n format: time\n" false
158+
159+
ty
160+
|> shouldEqual(typedefof<Option<_>>.MakeGenericType(typeof<TimeOnly>))
161+
139162
[<Fact>]
140163
let ``optional Guid maps to Option<Guid>``() =
141164
let ty =
@@ -444,3 +467,35 @@ let ``PreferNullable: optional binary (base64) stays as plain Stream``() =
444467
compilePropertyTypeWith true " type: string\n format: binary\n" false
445468

446469
ty |> shouldEqual typeof<IO.Stream>
470+
471+
// ── PreferNullable + useDateOnly: value-type date/time formats use Nullable<T> ──────────────
472+
// When both provideNullable=true and useDateOnly=true, optional DateOnly/TimeOnly properties
473+
// should be wrapped in Nullable<T> (not Option<T>), consistent with other value types.
474+
475+
[<Fact>]
476+
let ``PreferNullable: optional DateOnly maps to Nullable<DateOnly> when useDateOnly is true``() =
477+
let ty =
478+
compilePropertyTypeWithNullableAndDateOnly " type: string\n format: date\n" false
479+
480+
ty |> shouldEqual typeof<System.Nullable<DateOnly>>
481+
482+
[<Fact>]
483+
let ``PreferNullable: required DateOnly is not wrapped when useDateOnly is true``() =
484+
let ty =
485+
compilePropertyTypeWithNullableAndDateOnly " type: string\n format: date\n" true
486+
487+
ty |> shouldEqual typeof<DateOnly>
488+
489+
[<Fact>]
490+
let ``PreferNullable: optional TimeOnly maps to Nullable<TimeOnly> when useDateOnly is true``() =
491+
let ty =
492+
compilePropertyTypeWithNullableAndDateOnly " type: string\n format: time\n" false
493+
494+
ty |> shouldEqual typeof<System.Nullable<TimeOnly>>
495+
496+
[<Fact>]
497+
let ``PreferNullable: required TimeOnly is not wrapped when useDateOnly is true``() =
498+
let ty =
499+
compilePropertyTypeWithNullableAndDateOnly " type: string\n format: time\n" true
500+
501+
ty |> shouldEqual typeof<TimeOnly>

0 commit comments

Comments
 (0)