Skip to content

Fix handling of DU members that are also DUs#901

Merged
jhendrixMSFT merged 1 commit into
Azure:mainfrom
jhendrixMSFT:du-hierarchy
Mar 13, 2026
Merged

Fix handling of DU members that are also DUs#901
jhendrixMSFT merged 1 commit into
Azure:mainfrom
jhendrixMSFT:du-hierarchy

Conversation

@jhendrixMSFT
Copy link
Copy Markdown
Member

Avoid spurious import statement for DU types when in unions.rs. Added Spector coverage for the impacted scenario.

Avoid spurious import statement for DU types when in unions.rs.
Added Spector coverage for the impacted scenario.
Copilot AI review requested due to automatic review settings March 13, 2026 17:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Rust emitter support for discriminated unions that contain other discriminated unions, and adds a new Spector test crate (“hierarchy-building”) to validate the behavior end-to-end.

Changes:

  • Update TCGC adapter + codemodel types to allow discriminated-union members to be either a Model or another DiscriminatedUnion.
  • Update union codegen to avoid generating invalid/self-conflicting use statements when a DU contains another DU.
  • Add new Spector test crate + integration tests for hierarchy-building, and bump @azure-tools/typespec-rust to 0.37.1 with changelog entry.

Reviewed changes

Copilot reviewed 10 out of 24 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/typespec-rust/src/tcgcadapter/adapter.ts Emits DU members as nested DUs when subtypes are themselves polymorphic.
packages/typespec-rust/src/codemodel/types.ts Broadens DU member type to DiscriminatedUnion | Model.
packages/typespec-rust/src/codegen/unions.ts Skips adding use for DU members to prevent self-import conflicts in unions.rs.
packages/typespec-rust/package.json Version bump to 0.37.1.
packages/typespec-rust/CHANGELOG.md Adds 0.37.1 (unreleased) entry describing the DU-nesting fix.
packages/typespec-rust/.scripts/tspcompile.js Registers new Spector input spector_hierarchy_building.
packages/typespec-rust/test/Cargo.toml Adds hierarchy-building crate to the test workspace.
packages/typespec-rust/test/Cargo.lock Adds lock entry for spector_hierarchy_building.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/Cargo.toml New Spector crate manifest for hierarchy-building scenario.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/lib.rs New crate entrypoint re-exporting generated code.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/mod.rs Generated module root for clients/models.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/clients/mod.rs Generated clients module exports.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/clients/hierarchy_building_client.rs Generated top-level client + subclient accessors.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/clients/hierarchy_building_animal_operations_client.rs Generated Animal operations client (PUT endpoints).
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/clients/hierarchy_building_dog_operations_client.rs Generated Dog operations client (PUT endpoint).
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/clients/hierarchy_building_pet_operations_client.rs Generated Pet operations client (PUT endpoints).
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/models/mod.rs Generated models module wiring.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/models/method_options.rs Generated method option structs for hierarchy-building operations.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/models/models.rs Generated Dog model.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/models/models_impl.rs Generated conversions + request-content helpers for models.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/models/unions.rs Generated discriminated unions (Animal, Pet) including nested DU membership.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/models/unions_impl.rs Generated request-content helpers for unions.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/src/generated/models/unions_serde.rs Generated custom Serialize for extensible polymorphic unions.
packages/typespec-rust/test/spector/azure/client-generator-core/hierarchy-building/tests/hierarchy_building_tests.rs New integration tests covering DU nesting + request/response roundtrips.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@jhendrixMSFT jhendrixMSFT merged commit c1b580e into Azure:main Mar 13, 2026
9 checks passed
@jhendrixMSFT jhendrixMSFT deleted the du-hierarchy branch March 13, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants