Skip to content

fix: multi-level @Legacy.flattenProperty generates incorrect sample code#3831

Merged
JialinHuang803 merged 2 commits intoAzure:mainfrom
JialinHuang803:fix/multi-level-flatten-sample-3828
Mar 11, 2026
Merged

fix: multi-level @Legacy.flattenProperty generates incorrect sample code#3831
JialinHuang803 merged 2 commits intoAzure:mainfrom
JialinHuang803:fix/multi-level-flatten-sample-3828

Conversation

@JialinHuang803
Copy link
Copy Markdown
Member

Fix

Resolves #3828

When multiple @Legacy.flattenProperty decorators are applied at different nesting levels connected through non-flatten properties, the sample generator only applied the outer-level flatten. The inner flatten remained as a nested object, causing TS2353 compile errors.

Root Cause

In emitSamples.ts, enableFlatten: false set when processing a flattened property leaked through the else branch (non-flatten properties) to all deeper levels, blocking independent inner flatten operations.

Fix

In the else branch, strip enableFlatten: false from options before recursing deeper. This keeps consecutive/transition flatten blocked at the direct child level while allowing independent multi-level flattens to work correctly.

Changes

File Change
packages/typespec-ts/src/modular/emitSamples.ts Strip enableFlatten: false in else branch to prevent leaking to deeper levels
packages/typespec-ts/test/modularUnit/scenarios/samples/propertyFlatten/mulipleFlattenCases.md Add test case for independent multi-level flatten

Validation

  • All 855 unit tests passing (546 modular + 309 RLC)
  • Existing transition test case still produces correct output (consecutive flatten remains unsupported)
  • New test case verifies independent multi-level flatten works in samples

When multiple @legacy.flattenProperty decorators are applied at different
nesting levels connected through non-flatten properties, the sample
generator only applied the outer-level flatten. The inner flatten remained
as a nested object, causing TS2353 compile errors.

Root cause: enableFlatten:false set when processing a flattened property
leaked through the else branch (non-flatten properties) to all deeper
levels, blocking independent inner flatten operations.

Fix: In the else branch, strip enableFlatten:false from options before
recursing deeper. This keeps consecutive/transition flatten blocked at the
direct child level while allowing independent multi-level flattens to work.

Fixes Azure#3828

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JialinHuang803 JialinHuang803 enabled auto-merge (squash) March 11, 2026 02:15
@JialinHuang803 JialinHuang803 merged commit 1b90a33 into Azure:main Mar 11, 2026
16 checks passed
@JialinHuang803 JialinHuang803 deleted the fix/multi-level-flatten-sample-3828 branch March 11, 2026 05:06
JialinHuang803 added a commit to JialinHuang803/autorest.typescript that referenced this pull request Apr 9, 2026
…ode (Azure#3831)

When multiple @legacy.flattenProperty decorators are applied at different
nesting levels connected through non-flatten properties, the sample
generator only applied the outer-level flatten. The inner flatten remained
as a nested object, causing TS2353 compile errors.

Root cause: enableFlatten:false set when processing a flattened property
leaked through the else branch (non-flatten properties) to all deeper
levels, blocking independent inner flatten operations.

Fix: In the else branch, strip enableFlatten:false from options before
recursing deeper. This keeps consecutive/transition flatten blocked at the
direct child level while allowing independent multi-level flattens to work.

Fixes Azure#3828

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Multi-level @Legacy.flattenProperty generates incorrect sample code (TS2353)

2 participants