Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@azure-tools/azure-http-specs"
---

Add test cases for flatten property with unknown type and read-only properties.
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,87 @@ op putFlattenModel(@body input: FlattenModel): FlattenModel;
""")
@put
op putNestedFlattenModel(@body input: NestedFlattenModel): NestedFlattenModel;

@doc("This is the model with unknown type properties to be flattened.")
model FlattenUnknownModel {
name: string;

#suppress "@azure-tools/typespec-azure-core/no-unknown" "For testing purposes"
#suppress "@azure-tools/typespec-azure-core/no-legacy-usage" "Testing backcompat"
@global.Azure.ClientGenerator.Core.Legacy.flattenProperty
properties?: unknown;
Comment thread
MaryGao marked this conversation as resolved.
}

@scenario
@route("/flattenUnknownModel")
@scenarioDoc("""
Update and receive model with flatten property of unknown type.
Expected input body:
```json
{
"name": "foo"
}
```

Expected response body:
```json
{
"name": "test",
"properties": {
"key1": "value1",
"key2": "value2"
}
}
```
""")
@put
op putFlattenUnknownModel(@body input: FlattenUnknownModel): FlattenUnknownModel;

@doc("This is the model with all read-only properties to be flattened.")
model SolutionProperties {
@visibility(Lifecycle.Read)
solutionId?: string;

@visibility(Lifecycle.Read)
title?: string;

@visibility(Lifecycle.Read)
content?: string;
}

@doc("This is the model with flattened properties that are all read-only.")
model Solution {
name: string;

#suppress "@azure-tools/typespec-azure-core/no-legacy-usage" "Testing backcompat"
@global.Azure.ClientGenerator.Core.Legacy.flattenProperty
properties: SolutionProperties;

#suppress "@azure-tools/typespec-azure-core/no-legacy-usage" "Testing backcompat"
@global.Azure.ClientGenerator.Core.Legacy.flattenProperty
propertiesOptional?: SolutionProperties;
}

@scenario
@route("/flattenReadOnlyModel")
@scenarioDoc("""
Test model with flatten property containing all read-only properties.
Comment thread
MaryGao marked this conversation as resolved.
Comment thread
MaryGao marked this conversation as resolved.
Expected input body:
```json
{
"name": "foo"
}
```

Expected response body:
```json
{
"name": "foo",
"solutionId": "solution1",
"title": "Solution Title",
"content": "Solution Content"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(1) the response body shall be wrapped with properties or propertiesOptional
(2) one little question: is there any real service use flatten pattern of this PR? If yes, pls show the link and python may need also take a look.

@v-jiaodi v-jiaodi Mar 2, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@msyyc Please help review #4006

}
```
""")
@put
op putFlattenReadOnlyModel(@body body: Solution): Solution;
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,34 @@ Scenarios.Azure_ClientGenerator_Core_FlattenProperty_putNestedFlattenModel = pas
},
),
);

Scenarios.Azure_ClientGenerator_Core_FlattenProperty_putFlattenUnknownModel = passOnSuccess(
createMockApiDefinitions(
"flattenUnknownModel",
{
name: "foo",
},
{
name: "test",
properties: {
key1: "value1",
key2: "value2",
},
},
),
);

Scenarios.Azure_ClientGenerator_Core_FlattenProperty_putFlattenReadOnlyModel = passOnSuccess(
createMockApiDefinitions(
"flattenReadOnlyModel",
{
name: "foo",
},
{
name: "foo",
solutionId: "solution1",
title: "Solution Title",
content: "Solution Content",
},
),
);
Loading