fix: relax back compat param name matching - #11491
Merged
jorgerangel-msft merged 3 commits intoJul 30, 2026
Merged
Conversation
commit: |
Contributor
|
No changes needing a change description found. |
Contributor
There was a problem hiding this comment.
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.RestorePreviousParameterNamesto 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
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
jorgerangel-msft
marked this pull request as ready for review
July 30, 2026 20:24
jorgerangel-msft
requested review from
JoshLove-msft,
joseharriaga,
jsquire and
m-nash
as code owners
July 30, 2026 20:24
JoshLove-msft
approved these changes
Jul 30, 2026
jorgerangel-msft
enabled auto-merge
July 30, 2026 20:32
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.
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