Skip to content

fix: relax back compat param name matching - #11491

Merged
jorgerangel-msft merged 3 commits into
microsoft:mainfrom
jorgerangel-msft:relax-backcompat
Jul 30, 2026
Merged

fix: relax back compat param name matching#11491
jorgerangel-msft merged 3 commits into
microsoft:mainfrom
jorgerangel-msft:relax-backcompat

Conversation

@jorgerangel-msft

@jorgerangel-msft jorgerangel-msft commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Relaxes the back compat restoration of parameter names in methods. Previously, we only match a param to a previous signature's param if the current param's wire name matched the previous. Though there are still cases where the wire name changes and we would want the public surface of these methods to still not be unchanged from previous.

fixes: #11500

@jorgerangel-msft
jorgerangel-msft requested a review from Copilot July 30, 2026 18:02
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Jul 30, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@11491

commit: 55825aa

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

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.

Pull request overview

This PR adjusts the C# generator’s back-compat parameter name restoration to allow a signature-based (positional) fallback when the previously-published parameter name can’t be discovered via the spec/original name, and adds coverage to validate the new behavior.

Changes:

  • Update BackCompatHelper.RestorePreviousParameterNames to fall back to matching last-contract methods by signature (ignoring parameter names) and restoring parameter names positionally when name-based lookup fails.
  • Refine existing test coverage to ensure positional fallback does not occur when there is no matching last-contract signature.
  • Add a new test + test data to validate restoring a renamed parameter purely via signature match.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TypeProviderTests.cs Updates an existing scenario and adds a new unit test covering signature-based parameter-name restore.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TestData/TypeProviderTests/BuildMethodsForBackCompatibilityRestoresRenamedParameterBySignatureMatch/TestClient.cs Adds last-contract input type for the new signature-match restore scenario.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TestData/TypeProviderTests/BuildMethodsForBackCompatibilityRestoresRenamedParameterBySignatureMatch.cs Adds expected generated output asserting the restored parameter name.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TestData/TypeProviderTests/BuildMethodsForBackCompatibilityKeepsUnpublishedParameterName/TestClient.cs Adjusts the last-contract shape to ensure no signature match exists for the “keep name” test.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Utilities/BackCompatHelper.cs Implements the relaxed matching logic to restore parameter names by signature when needed.
Comments suppressed due to low confidence (1)

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Utilities/BackCompatHelper.cs:188

  • This comment is now misleading: the positional fallback runs not only for synthesized parameters, but also when we can’t map by OriginalName (e.g., when a different generator renamed the parameter). Update the comment to match the behavior.
                    // Fall back to a positional match for synthesized parameters

jorgerangel-msft and others added 2 commits July 30, 2026 13:10
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@jorgerangel-msft
jorgerangel-msft marked this pull request as ready for review July 30, 2026 20:24
@jorgerangel-msft
jorgerangel-msft added this pull request to the merge queue Jul 30, 2026
Merged via the queue into microsoft:main with commit 7a6b368 Jul 30, 2026
29 checks passed
@jorgerangel-msft
jorgerangel-msft deleted the relax-backcompat branch July 30, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relax Back Compat Method Param Matching

3 participants