Skip to content

[Mgmt] Fix nested flattened collection constructor arguments - #63266

Open
Wei Hu (live1206) wants to merge 2 commits into
mainfrom
issue-63263-flattened-collection
Open

Wei Hu (live1206) wants to merge 2 commits into
mainfrom
issue-63263-flattened-collection

Conversation

@live1206

@live1206 Wei Hu (live1206) commented Sep 22, 2026

Copy link
Copy Markdown
Member

Description

Fixes constructor generation for nested collection properties that pass through both explicit property flattening and automatic safe flattening. When an outer public constructor exposes IEnumerable<T> but the nested constructor requires IList<T>, the generator now materializes the argument with .ToList().

The shared argument-building helper also consolidates the duplicated name-match and type-match conversion logic.

Adds an end-to-end TypeSpec regression fixture that reproduces the Cosmos DB constructor chain from #63263.

Fixes #63263

Validation

  • pwsh eng/packages/http-client-csharp-mgmt/eng/scripts/Generate.ps1 -filter Mgmt-TypeSpec
  • dotnet test eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/test/Azure.Generator.Mgmt.Tests.csproj --filter FullyQualifiedName~FlattenPropertyVisitorTests --no-restore

@github-actions github-actions Bot added CodeGen Issues that relate to code generation Mgmt This issue is related to a management-plane library. labels Sep 22, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@live1206
Wei Hu (live1206) force-pushed the issue-63263-flattened-collection branch from 6e4ed04 to 911f55f Compare September 22, 2026 07:51
@live1206
Wei Hu (live1206) marked this pull request as ready for review September 22, 2026 08:14
Copilot AI balanced review requested due to automatic review settings September 22, 2026 08:14
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The generator conversion is correctly scoped and the regenerated fixture verifies the previously incompatible constructor chain.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes management generator constructor calls by materializing IEnumerable<T> as IList<T> when required by nested flattened models.

Changes:

  • Consolidates flattened constructor argument conversion.
  • Adds .ToList() for incompatible collection interfaces.
  • Adds a TypeSpec regression fixture and regenerated outputs.

Package versioning and released-API compatibility checks are not applicable to this generator-only change.

File Description
FlattenPropertyVisitor.cs Adds shared argument conversion and list materialization.
nested-flattened-collection.tsp Defines the regression scenario.
main.tsp Imports the new fixture.
NestedFlattenedCollectionOperationsRestOperations.cs Generated REST operation.
NestedFlattenedCollectionResource.Serialization.cs Generated resource serialization.
NestedFlattenedCollectionResource.cs Generated collection wrapper.
NestedFlattenedCollectionProperties.Serialization.cs Generated properties serialization.
NestedFlattenedCollectionProperties.cs Generated nested properties model.
NestedFlattenedCollectionItem.Serialization.cs Generated item serialization.
NestedFlattenedCollectionItem.cs Generated collection item.
NestedFlattenedCollectionContent.Serialization.cs Generated request serialization.
NestedFlattenedCollectionContent.cs Demonstrates the corrected .ToList() call.
AzureGeneratorMgmtTypeSpecTestsContext.cs Registers generated models.
MgmtTypeSpecTestsModelFactory.cs Adds model factory methods.
FooResource.cs Exposes generated regression operations.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CodeGen Issues that relate to code generation Mgmt This issue is related to a management-plane library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Mgmt][CodeGen] Flattened nested collection generates incompatible IEnumerable/IList constructors

2 participants