Add Spector case for Flatten property#3722
Merged
v-jiaodi merged 19 commits intoAzure:mainfrom Mar 12, 2026
Merged
Conversation
…nto add-flatten-case
Member
|
Should be merged Azure/typespec-azure#3729 |
v-jiaodi
commented
Mar 5, 2026
Comment on lines
+505
to
+524
| // For flatten properties, if all properties are readonly, return empty object | ||
| // Otherwise, return the item itself | ||
| if (options.flatten) { | ||
| // Change parameter name to _item to indicate it's intentionally unused | ||
| serializerFunction.parameters = [ | ||
| { | ||
| name: "_item", | ||
| type: options.flatten | ||
| ? resolveReference(refkey(options.flatten.baseModel)) | ||
| : resolveReference(refkey(type)) | ||
| } | ||
| ]; | ||
| output.push(` | ||
| return {}; | ||
| `); | ||
| } else { | ||
| output.push(` | ||
| return item; | ||
| `); | ||
| } |
Member
Author
MaryGao
reviewed
Mar 5, 2026
packages/typespec-ts/test/modularUnit/scenarios/models/serialization/readonlyFlattenModel.md
Outdated
Show resolved
Hide resolved
MaryGao
reviewed
Mar 9, 2026
| output.push(` | ||
| return ${serializeContent} | ||
| `); | ||
| } else if (options.flatten) { |
Member
There was a problem hiding this comment.
why this is for all read-only ones?
do we have a case for not all read-only ones?
Member
Author
There was a problem hiding this comment.
add ut for not all read-only ones
Member
Author
There was a problem hiding this comment.
Readonly property has already been excluded in getRequestModelProperties. https://github.com/Azure/autorest.typescript/blob/main/packages/typespec-ts/src/modular/helpers/operationHelpers.ts#L2145

MaryGao
reviewed
Mar 11, 2026
packages/typespec-ts/src/modular/serialization/buildSerializerFunction.ts
Show resolved
Hide resolved
Co-authored-by: Mary Gao <yanmeigao1210@gmail.com>
MaryGao
approved these changes
Mar 11, 2026
v-jiaodi
commented
Mar 11, 2026
| return ${serializeContent} | ||
| `); | ||
| } else if (options.flatten) { | ||
| } else if (propertiesStr.length && options.flatten) { |
Member
Author
There was a problem hiding this comment.
This logic is the same as the first one, which means this code path will never be executed.
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.

related pr: Azure/typespec-azure#3729
add case: