Skip to content

Commit 682c5c5

Browse files
github-actions[bot]Copilotsergey-tihon
authored
[repo-assist] test: add async IO.Stream and non-200 2xx response return-type tests (+3 tests, 465→468) (#453)
* test: add async IO.Stream and non-200 2xx response return-type tests (+3 tests, 465→468) Three new unit tests covering previously untested code paths in OperationCompiler: 1. asAsync=true + application/octet-stream response → Async<IO.Stream> Exercises the async branch of the IO.Stream response path (OperationCompiler.fs line ~488: awaitTask responseStream). 2. 201-only JSON response (no 200 defined) → Task<string> Exercises the 2xx fallback in the okResponse selection logic (the Seq.tryFind for codes in [200,300) branch). 3. 201-only JSON response in async mode → Async<string> Combines the two above — async mode + non-200 2xx fallback. Total unit tests: 465 → 468. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger checks --------- 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: Sergey Tihon <sergey.tihon@gmail.com>
1 parent 9a6a87f commit 682c5c5

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

‎tests/SwaggerProvider.Tests/Schema.OperationCompilationTests.fs‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,3 +1112,86 @@ let ``ignoreOperationId=true does not generate the original operationId as metho
11121112
let methodNames = allMethods |> List.map(fun m -> m.Name)
11131113
methodNames |> shouldNotContain "ListAllPets"
11141114
methodNames |> shouldNotContain "GetPetById"
1115+
1116+
// ── asAsync=true: octet-stream response produces Async<IO.Stream> ─────────────
1117+
1118+
let private octetStreamResponseAsyncSchema =
1119+
"""openapi: "3.0.0"
1120+
info:
1121+
title: OctetStreamResponseAsyncTest
1122+
version: "1.0.0"
1123+
paths:
1124+
/download:
1125+
get:
1126+
operationId: downloadData
1127+
responses:
1128+
"200":
1129+
description: File data
1130+
content:
1131+
application/octet-stream:
1132+
schema:
1133+
type: string
1134+
format: binary
1135+
components:
1136+
schemas: {}
1137+
"""
1138+
1139+
[<Fact>]
1140+
let ``asAsync=true: octet-stream response produces Async<IO.Stream> return type``() =
1141+
let types = compileAsyncSchema octetStreamResponseAsyncSchema
1142+
let method = (findMethod types "DownloadData").Value
1143+
method.ReturnType.IsGenericType |> shouldEqual true
1144+
1145+
method.ReturnType.GetGenericTypeDefinition()
1146+
|> shouldEqual typedefof<Async<_>>
1147+
1148+
method.ReturnType.GetGenericArguments()[0]
1149+
|> shouldEqual typeof<IO.Stream>
1150+
1151+
// ── Non-200 2xx response used as return type ───────────────────────────────────
1152+
// The okResponse lookup in OperationCompiler falls back to any 2xx code when
1153+
// there is no explicit "200" response defined. These tests exercise that path.
1154+
1155+
let private created201ResponseSchema =
1156+
"""openapi: "3.0.0"
1157+
info:
1158+
title: Created201Test
1159+
version: "1.0.0"
1160+
paths:
1161+
/items:
1162+
post:
1163+
operationId: createItem
1164+
responses:
1165+
"201":
1166+
description: Created
1167+
content:
1168+
application/json:
1169+
schema:
1170+
type: string
1171+
components:
1172+
schemas: {}
1173+
"""
1174+
1175+
[<Fact>]
1176+
let ``201 response with JSON body resolves to Task<string> when no 200 defined``() =
1177+
let types = compileTaskSchema created201ResponseSchema
1178+
let method = (findMethod types "CreateItem").Value
1179+
method.ReturnType.IsGenericType |> shouldEqual true
1180+
1181+
method.ReturnType.GetGenericTypeDefinition()
1182+
|> shouldEqual typedefof<Task<_>>
1183+
1184+
method.ReturnType.GetGenericArguments()[0]
1185+
|> shouldEqual typeof<string>
1186+
1187+
[<Fact>]
1188+
let ``201 response in async mode resolves to Async<string> when no 200 defined``() =
1189+
let types = compileAsyncSchema created201ResponseSchema
1190+
let method = (findMethod types "CreateItem").Value
1191+
method.ReturnType.IsGenericType |> shouldEqual true
1192+
1193+
method.ReturnType.GetGenericTypeDefinition()
1194+
|> shouldEqual typedefof<Async<_>>
1195+
1196+
method.ReturnType.GetGenericArguments()[0]
1197+
|> shouldEqual typeof<string>

0 commit comments

Comments
 (0)