Preserve accessible serialization constructors during back compat - #11798
Merged
JoshLove-msft merged 4 commits intoSep 1, 2026
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 00636c74-c4f7-434a-8a70-fb0c3d221328
JoshLove-msft
requested review from
Jorge Rangel (jorgerangel-msft),
Jose Arriaga Maldonado (joseharriaga),
Jesse Squire (jsquire) and
m-nash
as code owners
September 1, 2026 01:20
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 00636c74-c4f7-434a-8a70-fb0c3d221328
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 00636c74-c4f7-434a-8a70-fb0c3d221328
Contributor
|
No changes needing a change description found. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines the C# generator’s API-compat constructor restoration logic so that back-compat processing does not introduce a duplicate parameterless constructor when one already exists on a generated serialization partial (including cases where a visitor has made that constructor public). This directly targets the constructor churn scenario seen when ApiCompatVersion is enabled.
Changes:
- Update model back-compat constructor restoration to treat an accessible parameterless constructor on any serialization provider partial as already satisfying the contract.
- Add focused ClientModel tests covering:
- preserving an accessible parameterless serialization constructor (including visitor-customized routing),
- retaining the existing behavior of replacing an inaccessible parameterless serialization constructor by restoring one on the model partial.
- Update backward-compat documentation to clarify the “already exists” condition and the mocking-constructor removal behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/ModelProvider.cs | Avoid restoring a parameterless constructor onto the model partial when an accessible parameterless constructor already exists on a serialization partial. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/BackCompat_AccessibleParameterlessSerializationConstructorIsPreserved/MockInputModel.cs | Adds last-contract custom code fixture defining a published public parameterless constructor. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/ScmModelProviderTests.cs | Adds/extends tests validating preservation vs. replacement behavior for parameterless serialization constructors under back-compat. |
| packages/http-client-csharp/generator/docs/backward-compatibility.md | Clarifies docs for parameterless-constructor restoration eligibility and mocking-constructor removal semantics. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
commit: |
Copilot started reviewing on behalf of
Jorge Rangel (jorgerangel-msft)
September 1, 2026 16:02
View session
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Jorge Rangel (jorgerangel-msft)
approved these changes
Sep 1, 2026
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.
Summary
This addresses the constructor churn observed in openai/openai-dotnet#1341 when ApiCompatVersion is enabled.
Validation
npm run buildeng/scripts/Generate.ps1npm testnpm run cop