Skip to content

[Repo Assist] feat: add CancellationToken support to SwaggerClientProvider (v2) generated methods#348

Closed
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/feat-cancellationtoken-v2-issue-212-2026-03-29-a8f5a63-8b987d45b206d899
Closed

[Repo Assist] feat: add CancellationToken support to SwaggerClientProvider (v2) generated methods#348
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/feat-cancellationtoken-v2-issue-212-2026-03-29-a8f5a63-8b987d45b206d899

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is a Repo Assist automated PR.

Follow-up to #336 which added CancellationToken support to v3 OpenApiClientProvider. This change brings the same capability to the v2 SwaggerClientProvider.

Before: Generated v2 methods had no way to cancel in-flight HTTP requests.
After: Every generated method has an optional cancellationToken parameter (defaulting to CancellationToken.None). Existing code continues to work unchanged.

// Existing code — still works, uses CancellationToken.None
let! result = client.GetPet(1L)

// New — pass your own token
use cts = new CancellationTokenSource(TimeSpan.FromSeconds(5.0))
let! result = client.GetPet(1L, cts.Token)

Design

Same pattern as v3 (#336):

  1. ctArgIndex is set to List.length openApiParams so CT is always appended last.
  2. A UniqueNameGenerator seeded with existing parameter names produces a collision-free CT parameter name (cancellationToken, cancellationToken1, …).
  3. In invokeCode, the CT arg is extracted by position (List.item ctArgIndex allArgs) and the remaining args are forwarded to the OpenAPI parameter matching logic.
  4. The action quotation calls this.CallAsync(msg, [||], [||], %ct) — the same ProvidedApiClientBase.CallAsync overload used by v3, which passes the CT to HttpClient.SendAsync. Empty error-code arrays are passed since v2 schemas do not have the same error-response metadata structure as v3.

Changes

File Change
src/SwaggerProvider.DesignTime/v2/OperationCompiler.fs Compute ctArgIndex; append CT ProvidedParameter; extract CT in invokeCode; call this.CallAsync with CT
tests/SwaggerProvider.ProviderTests/v2/Swashbuckle.CancellationToken.Tests.fs New. 10 integration tests mirroring the v3 CT test suite
tests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsproj Added new CT test file

Test Status

Unit tests: 241 passed, 0 failed (unchanged)
Format check (dotnet fantomas --check): passed
⚠️ Integration tests (SwaggerProvider.ProviderTests): The test server (Swashbuckle.WebApi.Server) aborts on startup in this CI environment. This is a pre-existing infrastructure constraint — the same issue would affect any PR trying to run integration tests here. The logic of the CT change is the same as v3 (#336), which passed full integration tests when merged.

Scope

Only v2 SwaggerClientProvider is modified. The v3 OpenApiClientProvider already has CT support from #336.

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@4957663821dbb3260348084fa2f1659701950fef

Generated by 🌈 Repo Assist at {run-started}. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1f672aef974f4246124860fc532f82fe8a93a57e

…erated methods

Follow-up to #336 which added CancellationToken support to the v3
OpenApiClientProvider. This change brings the same capability to the
v2 SwaggerClientProvider.

Every generated method now has an optional cancellationToken parameter
appended last (defaulting to CancellationToken.None), so existing code
continues to compile without changes.

Changes:
- v2/OperationCompiler.fs: compute ctArgIndex, append CT ProvidedParameter,
  extract CT in invokeCode, use this.CallAsync(msg, [], [], ct) so the
  CancellationToken flows through to HttpClient.SendAsync — consistent
  with the v3 pattern.
- v2/Swashbuckle.CancellationToken.Tests.fs: 10 integration tests mirroring
  the v3 CT test suite (with/without CT, cancelled token, async variant).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant