[Repo Assist] feat: add CancellationToken support to SwaggerClientProvider (v2) generated methods#348
Closed
github-actions[bot] wants to merge 2 commits intomasterfrom
Conversation
…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>
15 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is a Repo Assist automated PR.
Follow-up to #336 which added
CancellationTokensupport to v3OpenApiClientProvider. This change brings the same capability to the v2SwaggerClientProvider.Before: Generated v2 methods had no way to cancel in-flight HTTP requests.
After: Every generated method has an optional
cancellationTokenparameter (defaulting toCancellationToken.None). Existing code continues to work unchanged.Design
Same pattern as v3 (#336):
ctArgIndexis set toList.length openApiParamsso CT is always appended last.UniqueNameGeneratorseeded with existing parameter names produces a collision-free CT parameter name (cancellationToken,cancellationToken1, …).invokeCode, the CT arg is extracted by position (List.item ctArgIndex allArgs) and the remaining args are forwarded to the OpenAPI parameter matching logic.actionquotation callsthis.CallAsync(msg, [||], [||], %ct)— the sameProvidedApiClientBase.CallAsyncoverload used by v3, which passes the CT toHttpClient.SendAsync. Empty error-code arrays are passed since v2 schemas do not have the same error-response metadata structure as v3.Changes
src/SwaggerProvider.DesignTime/v2/OperationCompiler.fsctArgIndex; append CTProvidedParameter; extract CT ininvokeCode; callthis.CallAsyncwith CTtests/SwaggerProvider.ProviderTests/v2/Swashbuckle.CancellationToken.Tests.fstests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsprojTest Status
✅ Unit tests: 241 passed, 0 failed (unchanged)
⚠️ Integration tests (
✅ Format check (
dotnet fantomas --check): passedSwaggerProvider.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
SwaggerClientProvideris modified. The v3OpenApiClientProvideralready has CT support from #336.