Skip to content

Enable client redirects in the Swagger client template - #17625

Merged
wfurt merged 1 commit into
dotnet:mainfrom
wfurt:wfurt/swagger-client-redirect
Oct 9, 2026
Merged

wfurt merged 1 commit into
dotnet:mainfrom
wfurt:wfurt/swagger-client-redirect

Conversation

@wfurt

@wfurt wfurt commented Sep 27, 2026

Copy link
Copy Markdown
Member

Generated clients only accept 2xx, so an endpoint that answers with a redirect to storage instead of the content fails. Fetching Helix console output reports:

RestApiException: The response contained an invalid status code 302 Found

Why this is back

This was fixed once in #15599, but that change was made in generated-code/HelixApi.cs. Regenerating that file removed it. The argument is absent from current main:

return HttpPipelineBuilder.Build(options, Array.Empty<HttpPipelinePolicy>(), Array.Empty<HttpPipelinePolicy>(), new HelixApiResponseClassifier());

and from every shipped Microsoft.DotNet.Helix.Client package I checked (10.0.0-beta.26468.2, 11.0.0-beta.26425.1, 12.0.0-beta.26475.4 — none contain HttpPipelineTransportOptions). So the bug returned silently after #15599 shipped.

This change

  • Fixes it in ServiceClient.hb so it survives regeneration and applies to every generated client, not just Helix.
  • Regenerates the affected Helix output so it takes effect without waiting for an unrelated regeneration. The emitted line matches the template exactly; the rationale is a Handlebars comment, so generated output stays clean.

Security note

Azure.Core drops the Authorization header when a redirect crosses to another host, so the service token is not sent to the redirect target. That is why fetching the same URL with curl -L already worked, and why #15599 hit a 403 when it tried replaying the request manually with the original header.

Validation

Verified the equivalent fix end to end by supplying a redirect-following transport from a caller and running osob-cli exec against a live queue: console output is returned instead of the exception.

Console log: 'echo-redirectfixwo' from job 2e922c5b-... (raspbian.11.arm32.iot.open)
REDIRECT_FIX_WORKS
['echo-redirectfixwo' END OF WORK ITEM LOG: Command exited with 0]

The generated clients only accept 2xx, so an endpoint that answers with a
redirect to storage instead of the content fails. Fetching Helix console output
reports "The response contained an invalid status code 302 Found".

This was fixed once in dotnet#15599, but the change was made in
generated-code/HelixApi.cs. Regenerating that file removed it, and it is absent
from current main and from every shipped Microsoft.DotNet.Helix.Client package,
so the bug came back unnoticed.

Fix it in ServiceClient.hb so it survives regeneration and applies to every
generated client, and regenerate the affected Helix output so it takes effect
without waiting for an unrelated regeneration.

Azure.Core drops the Authorization header when a redirect crosses to another
host, so the service token is not sent to the redirect target. That is why
fetching the same URL with curl -L already worked.

Co-authored-by: Copilot <[email protected]>
Copilot AI lite review requested due to automatic review settings September 27, 2026 20:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified that would block approval.

Review effort: Lite
Findings: None

What changed in this PR

Updates the Swagger C# client template to follow storage redirects and regenerates the Helix client accordingly.

Changes:

  • Enables HttpPipelineTransportOptions.IsClientRedirectEnabled.
  • Applies the fix to generated clients and refreshed Helix output.
File Description
src/​Microsoft.DotNet.SwaggerGenerator/​Microsoft.DotNet.SwaggerGenerator.CodeGenerator/​Languages/​csharp/​ServiceClient.hb Updated as part of this pull request.
src/​Microsoft.DotNet.Helix/​Client/​CSharp/​generated-code/​HelixApi.cs Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@wfurt
wfurt requested a review from mmitche September 27, 2026 21:53
@wfurt
wfurt merged commit 7dad901 into dotnet:main Oct 9, 2026
12 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants