fix: multi-level @Legacy.flattenProperty generates incorrect sample code#3831
Merged
JialinHuang803 merged 2 commits intoAzure:mainfrom Mar 11, 2026
Merged
Conversation
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>
MaryGao
approved these changes
Mar 11, 2026
Merged
10 tasks
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>
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.
Fix
Resolves #3828
When multiple
@Legacy.flattenPropertydecorators 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: falseset 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: falsefrom 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
packages/typespec-ts/src/modular/emitSamples.tsenableFlatten: falsein else branch to prevent leaking to deeper levelspackages/typespec-ts/test/modularUnit/scenarios/samples/propertyFlatten/mulipleFlattenCases.mdValidation