[http-client-csharp] Preserve previously-published parameter names across back-compat#10464
Merged
JoshLove-msft merged 10 commits intomicrosoft:mainfrom Apr 24, 2026
Conversation
…y methods when only param names change Integrates parameter-name preservation into the existing back-compat feature. When the only difference between a previous and current factory method is one or more parameter names (same method name, same parameter types in the same order, same count), the previous names are mutated in place on the current ParameterProvider so that the body and XML docs serialize with the preserved names. This avoids source-breaking changes for callers using named arguments when properties are renamed. Fixes microsoft#10463 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
Contributor
|
No changes needing a change description found. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
JoshLove-msft
commented
Apr 23, 2026
The backcompat lookup against LastContractView previously only ran for the paging-specific 'top -> maxCount' rename and the page-size casing normalization. Extend it so every parameter participates: when a service method's parameter has been renamed by the generator and the previous contract published a parameter with the original spec name, restore that name. Scope the search to methods whose name matches the current service method (allowing for the sync/async pair) so that a common parameter name shared across multiple methods can't false-match. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jorgerangel-msft
approved these changes
Apr 23, 2026
…ity.md Co-authored-by: Jorge Rangel <102122018+jorgerangel-msft@users.noreply.github.com>
When GetMethodCollectionByOperation switched _backCompatProvider it called the full Reset() on the ClientProvider, which discarded all properties, fields, constructors, and views. That wiped state previously injected by visitors (e.g. Azure DistributedTracingVisitor's ClientDiagnostics property) and caused downstream visitors such as LroVisitor to throw 'Sequence contains no matching element' when looking up the missing property. Introduce TypeProvider.ResetMethods() that only invalidates the cached methods and use it (plus RestClient.ResetMethods()) so the convenience/protocol methods rebuild with the new backcompat provider while leaving visitor-applied state intact. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…el-factory-param-names
…logger Address PR feedback: emit a Debug entry through the new BackCompatibilityChangeCategory.ParameterNamePreserved logging pipeline whenever the model factory rename-only fast path replaces a current parameter name with the previously-published name. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jorgerangel-msft
approved these changes
Apr 23, 2026
iscai-msft
pushed a commit
to iscai-msft/typespec
that referenced
this pull request
Apr 24, 2026
… when previous contract had same-typed params in different order (microsoft#10491) ## Problem PR microsoft#10464 introduced `ModelFactoryProvider.PreservePreviousParameterNames`, which positionally renames current factory-method parameters to match the previous contract whenever the method signatures match by name + parameter types. When the previous and current contracts both have two same-typed parameters but in **opposite order**, this positional rename silently swaps which parameter feeds which constructor field via the name-based lookup in `GetCtorArgs`. This is a real correctness regression and a source-breaking change. Concretely, `Azure.AI.VoiceLive.VoiceLiveModelFactory.SessionUpdateConversationItemDeleted` regenerates as: ```csharp public static SessionUpdateConversationItemDeleted SessionUpdateConversationItemDeleted(string itemId0 = default, string eventId0 = default) { return new SessionUpdateConversationItemDeleted(ServerEventType.ConversationItemDeleted, itemId0, additionalBinaryDataProperties: null, eventId0); } ``` Note `itemId0` is passed to the constructor's `eventId` field and `eventId0` to the `itemId` field — values silently end up in the wrong properties. Reproduced via the auto-generated Azure SDK PR Azure/azure-sdk-for-net#58632. ## Fix In `PreservePreviousParameterNames`, skip the rename when applying it would cause `previousName` to collide with another current parameter's current name. This preserves the legitimate casing/spec-rename use case (e.g. `metricname` -> `metricName`) while preventing the swap pathology. After the fix, the same factory regenerates correctly: ```csharp public static SessionUpdateConversationItemDeleted SessionUpdateConversationItemDeleted(string eventId = default, string itemId = default) { return new SessionUpdateConversationItemDeleted(ServerEventType.ConversationItemDeleted, eventId, additionalBinaryDataProperties: null, itemId); } ``` ## Tests Added `BackCompatibility_SwapTypeParamsDoesNotCorrupt` regression test covering the case where the previous contract has two same-typed parameters in swapped order. All 1434 Generator + 1312 ClientModel tests pass. --generated by Copilot --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Generalizes parameter-name preservation across the back-compat feature so that renamed parameters in both model factory methods and service method signatures continue to use their previously-published names.
Combines and supersedes #10465.
Fixes #10463
Model factory methods (
ModelFactoryProvider)When the only difference between a previous and current factory method is one or more parameter names (same method name, same parameter types in the same order, same count), the previous names are mutated in place on the current
ParameterProviderso that the body and XML docs serialize with the preserved names. This avoids source-breaking changes for callers using named arguments when properties are renamed.When a new property is added at the same time as a rename (parameter counts differ), the standard
[EditorBrowsable(EditorBrowsableState.Never)]overload is generated using the previously-published parameter names; renamed parameters that no longer match a current property are passed asdefaultto the constructor.Service method signatures (
RestClientProvider)The back-compat lookup against
LastContractViewpreviously only ran for the paging-specifictop -> maxCountrename and the page-size casing normalization. This PR extends it so every parameter participates: when a service method's parameter has been renamed by the generator and the previous contract published a parameter with the original spec name, restore that name. The search is scoped to methods whose name matches the current service method (allowing for the sync/async pair) so that a common parameter name shared across multiple methods can't false-match.Tests
ModelFactoryProviderTests.BackCompatibility_OnlyParamNameChanged(partial rename)ModelFactoryProviderTests.BackCompatibility_MultipleParamNamesChanged(all params renamed)ModelFactoryProviderTests.BackCompatibility_NewPropertyAddedWithRenamedParam(new property + rename)RestClientProviderTests.ParameterNamePreservedFromLastContractView(non-paging service method rename)Docs
Updated
backward-compatibility.mdwith two new scenarios: