Skip to content

Commit 826e3b8

Browse files
github-actions[bot]CopilotCopilotsergey-tihonCopilot
authored
[Repo Assist] refactor: return HttpResponseMessage from CallAsync and align generated response handling (#385)
* fix: expose HTTP response headers via LastResponseHeaders (closes #179) - Change CallAsync to return Task<HttpResponseMessage> instead of Task<HttpContent> - Add mutable LastResponseHeaders property to ProvidedApiClientBase so callers can inspect response headers after each operation call - Add collectResponseHeaders helper to RuntimeHelpers - Update OperationCompiler quotations to use response.Content where content was previously used directly - Add 4 new unit tests for LastResponseHeaders behaviour Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger checks * fix: remove LastResponseHeaders and keep CallAsync response return Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/7b6606ed-f420-4df8-9e59-bbfd17333974 Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> * Update tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs Co-authored-by: Copilot <175728472+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> 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> Co-authored-by: Sergey Tihon <sergey.tihon@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0d0d645 commit 826e3b8

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

src/SwaggerProvider.DesignTime/OperationCompiler.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ type OperationCompiler(schema: OpenApiDocument, defCompiler: DefinitionCompiler,
432432

433433
task {
434434
let! response = x
435-
let! content = RuntimeHelpers.readContentAsString response ct
435+
let! content = RuntimeHelpers.readContentAsString response.Content ct
436436
return (%this).Deserialize(content, innerReturnType)
437437
}
438438
@>
@@ -444,7 +444,7 @@ type OperationCompiler(schema: OpenApiDocument, defCompiler: DefinitionCompiler,
444444

445445
task {
446446
let! response = x
447-
let! data = RuntimeHelpers.readContentAsStream response ct
447+
let! data = RuntimeHelpers.readContentAsStream response.Content ct
448448
return data
449449
}
450450
@>
@@ -456,7 +456,7 @@ type OperationCompiler(schema: OpenApiDocument, defCompiler: DefinitionCompiler,
456456

457457
task {
458458
let! response = x
459-
let! data = RuntimeHelpers.readContentAsString response ct
459+
let! data = RuntimeHelpers.readContentAsString response.Content ct
460460
return data
461461
}
462462
@>

src/SwaggerProvider.Runtime/ProvidedApiClientBase.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ type ProvidedApiClientBase(httpClient: HttpClient, options: JsonSerializerOption
4646

4747
member this.CallAsync
4848
(request: HttpRequestMessage, errorCodes: string[], errorDescriptions: string[], cancellationToken: System.Threading.CancellationToken)
49-
: Task<HttpContent> =
49+
: Task<HttpResponseMessage> =
5050
task {
5151
let! response = this.HttpClient.SendAsync(request, cancellationToken)
5252

5353
if response.IsSuccessStatusCode then
54-
return response.Content
54+
return response
5555
else
5656
let code = response.StatusCode |> int
5757
let codeStr = code |> string

tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ module OpenApiExceptionTests =
563563
use handler = new StubHttpMessageHandler(HttpStatusCode.OK, "result")
564564
let client = makeClient handler
565565
use request = new HttpRequestMessage(HttpMethod.Get, "http://stub/pets/1")
566-
let! content = client.CallAsync(request, [||], [||], CancellationToken.None)
567-
let! body = content.ReadAsStringAsync()
566+
use! response = client.CallAsync(request, [||], [||], CancellationToken.None)
567+
let! body = response.Content.ReadAsStringAsync()
568568
body |> shouldEqual "result"
569569
}
570570

@@ -588,7 +588,6 @@ module OpenApiExceptionTests =
588588
()
589589
}
590590

591-
592591
/// Test types for formatObject tests — must be plain .NET classes with declared public properties.
593592
type FmtSingle(name: string) =
594593
member _.Name = name

0 commit comments

Comments
 (0)