Skip to content

Commit 7b25fdf

Browse files
[Repo Assist] eng: remove stale YamlDotNet dependency + test coverage for cookie params, text/plain and default responses (#386)
* eng: remove stale YamlDotNet dependency YamlDotNet was only used by the old v2 custom parser which was removed in PR #377. The paket.dependencies comment already said to delete it when the v2 parser was dropped. Microsoft.OpenApi.YamlReader (which uses SharpYaml internally) continues to handle YAML document parsing. All 281 unit tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test: add coverage for cookie params, text/plain and default responses (+6) Add unit tests for three previously untested OperationCompiler code paths: - Cookie parameters: verify that cookie params appear as method params, required cookies are non-optional, optional cookies are optional. - text/plain response: verify that an operation returning text/plain produces Task<string> (and Async<string> in async mode). - default response: verify that when no 2xx response is defined, the 'default' response is used to determine the return type. Total test count: 281 → 287. Co-authored-by: Copilot <223556219+Copilot@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>
1 parent 4b395e5 commit 7b25fdf

4 files changed

Lines changed: 145 additions & 10 deletions

File tree

paket.dependencies

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ nuget Microsoft.OpenApi ~> 2 # https://github.com/microsoft/OpenAPI.NET/blob/mai
99
nuget Microsoft.OpenApi.YamlReader
1010
nuget NETStandard.Library.NETFramework
1111

12-
# delete when we drop custom parser for v2
13-
nuget YamlDotNet
14-
1512
# THis lines are used by Paket to get the latest version of the Type Provider SDK files
1613
github fsprojects/FSharp.TypeProviders.SDK src/ProvidedTypes.fsi
1714
github fsprojects/FSharp.TypeProviders.SDK src/ProvidedTypes.fs

paket.lock

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ NUGET
4242
System.Threading.Tasks.Extensions (4.6.3) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) (&& (>= netstandard2.0) (< netstandard2.1))
4343
System.Runtime.CompilerServices.Unsafe (>= 6.1.2) - restriction: || (>= net462) (&& (< netcoreapp2.1) (>= netstandard2.0) (< netstandard2.1))
4444
System.ValueTuple (4.6.2) - restriction: >= net462
45-
YamlDotNet (16.3)
4645
GITHUB
4746
remote: fsprojects/FSharp.TypeProviders.SDK
48-
src/ProvidedTypes.fs (75ac6119896431f6573bfcfb663bac2fe3d3df63)
49-
src/ProvidedTypes.fsi (75ac6119896431f6573bfcfb663bac2fe3d3df63)
47+
src/ProvidedTypes.fs (bbea8e0f0858e8cc78159c248baf6bec0636ecfc)
48+
src/ProvidedTypes.fsi (bbea8e0f0858e8cc78159c248baf6bec0636ecfc)
5049
remote: fsprojects/FSharp.Data
51-
src/FSharp.Data.Runtime.Utilities/NameUtils.fs (a1ee1414cacb3d2e6fa26b2726a164f563502728)
52-
src/FSharp.Data.Runtime.Utilities/Pluralizer.fs (a1ee1414cacb3d2e6fa26b2726a164f563502728)
50+
src/FSharp.Data.Runtime.Utilities/NameUtils.fs (e4031d0ce7301da50ba15a5f5084ec9171d8200f)
51+
src/FSharp.Data.Runtime.Utilities/Pluralizer.fs (e4031d0ce7301da50ba15a5f5084ec9171d8200f)
5352
GROUP Server
5453
RESTRICTION: == net10.0
5554
NUGET

src/SwaggerProvider.DesignTime/paket.references

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ File: NameUtils.fs
55
System.Text.Json
66
Microsoft.OpenApi
77
Microsoft.OpenApi.YamlReader
8-
9-
YamlDotNet

tests/SwaggerProvider.Tests/Schema.OperationCompilationTests.fs

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,144 @@ let ``required header parameter is not optional``() =
499499
let headerParam = parameters |> Array.find(fun p -> p.Name = "xApiVersion")
500500
headerParam.IsOptional |> shouldEqual false
501501
headerParam.ParameterType |> shouldEqual typeof<string>
502+
503+
// ── Cookie parameters ──────────────────────────────────────────────────────────
504+
505+
let private cookieParamSchema =
506+
"""openapi: "3.0.0"
507+
info:
508+
title: CookieParamTest
509+
version: "1.0.0"
510+
paths:
511+
/session:
512+
get:
513+
operationId: getSession
514+
parameters:
515+
- name: sessionId
516+
in: cookie
517+
required: true
518+
schema:
519+
type: string
520+
- name: theme
521+
in: cookie
522+
required: false
523+
schema:
524+
type: string
525+
responses:
526+
"200":
527+
description: OK
528+
content:
529+
application/json:
530+
schema:
531+
type: string
532+
components:
533+
schemas: {}
534+
"""
535+
536+
[<Fact>]
537+
let ``cookie parameter is included as a method parameter``() =
538+
let types = compileTaskSchema cookieParamSchema
539+
let method = (findMethod types "GetSession").Value
540+
let parameters = method.GetParameters()
541+
// sessionId (required string) + theme (optional string) + cancellationToken
542+
parameters.Length |> shouldEqual 3
543+
let paramNames = parameters |> Array.map(fun p -> p.Name)
544+
paramNames |> shouldContain "sessionId"
545+
paramNames |> shouldContain "theme"
546+
547+
[<Fact>]
548+
let ``required cookie parameter is not optional``() =
549+
let types = compileTaskSchema cookieParamSchema
550+
let method = (findMethod types "GetSession").Value
551+
let parameters = method.GetParameters()
552+
let cookieParam = parameters |> Array.find(fun p -> p.Name = "sessionId")
553+
cookieParam.IsOptional |> shouldEqual false
554+
cookieParam.ParameterType |> shouldEqual typeof<string>
555+
556+
[<Fact>]
557+
let ``optional cookie parameter is optional``() =
558+
let types = compileTaskSchema cookieParamSchema
559+
let method = (findMethod types "GetSession").Value
560+
let parameters = method.GetParameters()
561+
let themeParam = parameters |> Array.find(fun p -> p.Name = "theme")
562+
themeParam.IsOptional |> shouldEqual true
563+
564+
// ── text/plain response ────────────────────────────────────────────────────────
565+
566+
let private textPlainResponseSchema =
567+
"""openapi: "3.0.0"
568+
info:
569+
title: TextPlainTest
570+
version: "1.0.0"
571+
paths:
572+
/health:
573+
get:
574+
operationId: getHealth
575+
responses:
576+
"200":
577+
description: OK
578+
content:
579+
text/plain:
580+
schema:
581+
type: string
582+
components:
583+
schemas: {}
584+
"""
585+
586+
[<Fact>]
587+
let ``text/plain response produces Task<string> return type``() =
588+
let types = compileTaskSchema textPlainResponseSchema
589+
let method = (findMethod types "GetHealth").Value
590+
method.ReturnType.IsGenericType |> shouldEqual true
591+
592+
method.ReturnType.GetGenericTypeDefinition()
593+
|> shouldEqual typedefof<Task<_>>
594+
595+
method.ReturnType.GetGenericArguments()[0]
596+
|> shouldEqual typeof<string>
597+
598+
[<Fact>]
599+
let ``text/plain response in async mode produces Async<string> return type``() =
600+
let types = compileAsyncSchema textPlainResponseSchema
601+
let method = (findMethod types "GetHealth").Value
602+
method.ReturnType.IsGenericType |> shouldEqual true
603+
604+
method.ReturnType.GetGenericTypeDefinition()
605+
|> shouldEqual typedefof<Async<_>>
606+
607+
method.ReturnType.GetGenericArguments()[0]
608+
|> shouldEqual typeof<string>
609+
610+
// ── default response ───────────────────────────────────────────────────────────
611+
612+
let private defaultResponseSchema =
613+
"""openapi: "3.0.0"
614+
info:
615+
title: DefaultResponseTest
616+
version: "1.0.0"
617+
paths:
618+
/data:
619+
get:
620+
operationId: getData
621+
responses:
622+
default:
623+
description: Default response
624+
content:
625+
application/json:
626+
schema:
627+
type: string
628+
components:
629+
schemas: {}
630+
"""
631+
632+
[<Fact>]
633+
let ``default response is used as return type when no 2xx response is defined``() =
634+
let types = compileTaskSchema defaultResponseSchema
635+
let method = (findMethod types "GetData").Value
636+
method.ReturnType.IsGenericType |> shouldEqual true
637+
638+
method.ReturnType.GetGenericTypeDefinition()
639+
|> shouldEqual typedefof<Task<_>>
640+
// The string schema from the default response should produce Task<string>
641+
method.ReturnType.GetGenericArguments()[0]
642+
|> shouldEqual typeof<string>

0 commit comments

Comments
 (0)