Use deterministic ordering for C# derived-model references - #11950
Open
JoshLove-msft with Copilot wants to merge 3 commits into
Open
Use deterministic ordering for C# derived-model references#11950JoshLove-msft with Copilot wants to merge 3 commits into
JoshLove-msft with Copilot wants to merge 3 commits into
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Ensure deterministic ordering in abstract models reference docs
Use deterministic ordering for C# derived-model references
Sep 11, 2026
JoshLove-msft
marked this pull request as ready for review
September 11, 2026 23:43
JoshLove-msft
requested review from
Jorge Rangel (jorgerangel-msft),
Jose Arriaga Maldonado (joseharriaga),
Jesse Squire (jsquire) and
m-nash
as code owners
September 11, 2026 23:43
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Add a fully qualified-name tie-breaker for same-named models to ensure ordering is deterministic.
Pull request overview
Updates C# derived-model documentation to use deterministic ordering and adds regression coverage.
Changes:
- Sorts derived models with ordinal comparison.
- Adds ordering and deduplication tests.
- Updates documentation expectations.
File summaries
| File | Reviewed change |
|---|---|
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelProviderTests.cs |
Adds ordering and deduplication coverage. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/DiscriminatorTests.cs |
Updates documentation expectations. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/ModelProvider.cs |
Applies deterministic derived-model sorting. |
Review details
Suppressed comments (1)
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/ModelProvider.cs:134
- This only orders by the simple generated name, so two valid derived models with the same name in different namespaces compare equal.
OrderBypreserves theHashSetorder for equal keys, leaving the fully qualified<see>references nondeterministic; add aThenByonm.Type.FullyQualifiedName(the value emitted in the documentation).
return [.. derivedModels.OrderBy(m => m.Name, StringComparer.Ordinal)];
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
|
Copilot you need to regenerate |
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Contributor
Author
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
One or more issues must be addressed before approval.
Review details
Suppressed comments (1)
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/ModelProvider.cs:134
- Sorting only by the short
Namedoes not make this fully deterministic: derived models can share a C# name when they come from different namespaces, while the documentation emitsType.FullyQualifiedName. For equal names,OrderBypreserves theHashSetiteration order, so reversed input can still reorder the references; add an ordinal tie-breaker on the fully qualified name (and cover that case).
return [.. derivedModels.OrderBy(m => m.Name, StringComparer.Ordinal)];
- Files reviewed: 3/6 changed files
- Comments generated: 0 new
- Review effort level: Lite
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.
Derived-model references in C# documentation inherit
HashSetenumeration order, risking unintended changes on regeneration.StringComparer.Ordinalfor culture-independent output.