-
Notifications
You must be signed in to change notification settings - Fork 71
Add flatten property tests for unknown type and read-only properties #3729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
46e6c85
dc9e8bb
260bfdf
0e65820
95952c1
24ee7fd
9e16dff
f176c0e
3d31702
75e5df5
11ea991
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
|---|---|---|
|
|
@@ -110,3 +110,103 @@ 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; | ||
| } | ||
|
|
||
| @scenario | ||
| @route("/flattenUnknownModel") | ||
| @scenarioDoc(""" | ||
| Update and receive model with flatten property of unknown type. | ||
|
|
||
| Note: `unknown` is a non-model type. The flatten decorator should be ignored for non-model types, | ||
| so whether flattened or not, the behavior should be the same. This test verifies that SDKs correctly | ||
| ignore flatten for non-model types. | ||
|
|
||
| Expected behavior: The `properties` field should NOT be flattened and should remain as-is in the model, | ||
| since flatten only applies to model types. | ||
|
|
||
| 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. | ||
MaryGao marked this conversation as resolved.
Show resolved
Hide resolved
MaryGao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
|
|
||
| Expected input body: | ||
| ```json | ||
| { | ||
| "name": "foo" | ||
| } | ||
| ``` | ||
|
|
||
| Expected response body (properties flattened to parent level): | ||
| ```json | ||
| { | ||
| "name": "foo", | ||
| "solutionId": "solution1", | ||
| "title": "Solution Title", | ||
| "content": "Solution Content" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (1) the response body shall be wrapped with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the first point, I’ll open a PR to fix it. properties unknown case:https://github.com/Azure/azure-rest-api-specs/blob/main/specification/eventhub/resource-manager/Microsoft.EventHub/Eventhub/models.tsp#L1608
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| ``` | ||
| """) | ||
| @put | ||
| op putFlattenReadOnlyModel(@body body: Solution): Solution; | ||
Uh oh!
There was an error while loading. Please reload this page.