diff --git a/.chronus/changes/fix-flatten-property-tests-2026-03-04-10-56-42.md b/.chronus/changes/fix-flatten-property-tests-2026-03-04-10-56-42.md new file mode 100644 index 0000000000..2fbe56ce69 --- /dev/null +++ b/.chronus/changes/fix-flatten-property-tests-2026-03-04-10-56-42.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/azure-http-specs" +--- + +Fix test cases for flatten property with read-only properties. diff --git a/packages/azure-http-specs/specs/azure/client-generator-core/flatten-property/main.tsp b/packages/azure-http-specs/specs/azure/client-generator-core/flatten-property/main.tsp index 7caf563c6b..5a92e439b4 100644 --- a/packages/azure-http-specs/specs/azure/client-generator-core/flatten-property/main.tsp +++ b/packages/azure-http-specs/specs/azure/client-generator-core/flatten-property/main.tsp @@ -172,11 +172,7 @@ model Solution { #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; + properties?: SolutionProperties; } @scenario @@ -186,7 +182,6 @@ model Solution { Expected behavior: When flattening a property that contains only read-only properties: - For input (write): Read-only properties should not appear in the input model, regardless of flattening - - For response (read): Read-only properties should be flattened to the parent model level The `properties` and `propertiesOptional` fields contain only read-only properties (`solutionId`, `title`, `content`). These should be flattened into the parent `Solution` model in the response. @@ -198,13 +193,15 @@ model Solution { } ``` - Expected response body (properties flattened to parent level): + Expected response body: ```json { "name": "foo", - "solutionId": "solution1", - "title": "Solution Title", - "content": "Solution Content" + "properties": { + "solutionId": "solution1", + "title": "Solution Title", + "content": "Solution Content" + } } ``` """) diff --git a/packages/azure-http-specs/specs/azure/client-generator-core/flatten-property/mockapi.ts b/packages/azure-http-specs/specs/azure/client-generator-core/flatten-property/mockapi.ts index 67547ad2b9..38d70be79a 100644 --- a/packages/azure-http-specs/specs/azure/client-generator-core/flatten-property/mockapi.ts +++ b/packages/azure-http-specs/specs/azure/client-generator-core/flatten-property/mockapi.ts @@ -86,9 +86,11 @@ Scenarios.Azure_ClientGenerator_Core_FlattenProperty_putFlattenReadOnlyModel = p }, { name: "foo", - solutionId: "solution1", - title: "Solution Title", - content: "Solution Content", + properties: { + solutionId: "solution1", + title: "Solution Title", + content: "Solution Content", + }, }, ), );