Skip to content

[http-client-csharp] Preserve previously-published parameter names across back-compat#10464

Merged
JoshLove-msft merged 10 commits intomicrosoft:mainfrom
JoshLove-msft:csharp/preserve-model-factory-param-names
Apr 24, 2026
Merged

[http-client-csharp] Preserve previously-published parameter names across back-compat#10464
JoshLove-msft merged 10 commits intomicrosoft:mainfrom
JoshLove-msft:csharp/preserve-model-factory-param-names

Conversation

@JoshLove-msft
Copy link
Copy Markdown
Contributor

@JoshLove-msft JoshLove-msft commented Apr 23, 2026

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 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.

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 as default to the constructor.

Service method signatures (RestClientProvider)

The back-compat lookup against LastContractView previously only ran for the paging-specific top -> maxCount rename 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)
  • Full ClientModel + Generator suites green (1312 + 1427 tests).

Docs

Updated backward-compatibility.md with two new scenarios:

  • Property Renamed / New Property Added Together with a Rename (model factory)
  • Method Parameter Name Preserved from Last Contract (service method signatures)

JoshLove-msft and others added 2 commits April 22, 2026 18:44
…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>
@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 Apr 23, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 23, 2026

Open in StackBlitz

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

commit: dd2e526

@github-actions
Copy link
Copy Markdown
Contributor

No changes needing a change description found.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JoshLove-msft JoshLove-msft enabled auto-merge April 23, 2026 02:09
Comment thread packages/http-client-csharp/generator/docs/backward-compatibility.md Outdated
JoshLove-msft and others added 3 commits April 22, 2026 19:44
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>
@JoshLove-msft JoshLove-msft changed the title [http-client-csharp] Preserve previous parameter names on ModelFactor… [http-client-csharp] Preserve previously-published parameter names across back-compat Apr 23, 2026
Comment thread packages/http-client-csharp/generator/docs/backward-compatibility.md Outdated
JoshLove-msft and others added 2 commits April 23, 2026 10:34
…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>
JoshLove-msft and others added 2 commits April 23, 2026 15:20
…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>
@JoshLove-msft JoshLove-msft added this pull request to the merge queue Apr 23, 2026
Merged via the queue into microsoft:main with commit cb943e7 Apr 24, 2026
29 checks passed
@JoshLove-msft JoshLove-msft deleted the csharp/preserve-model-factory-param-names branch April 24, 2026 00:04
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.

[http-client-csharp] Preserve original parameter names in ModelFactory when properties are renamed

2 participants