Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/typespec-ts/src/modular/emitSamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,15 @@ function getParameterValue(
propRetValue =
paramValue.length > 2 ? paramValue.slice(1, -1) : undefined;
} else {
// Don't propagate enableFlatten:false to deeper levels — it's only
// meant to block consecutive (transition) flatten at the direct child
// level. Non-flatten properties should recurse with default behavior
// so that independent inner flattens at deeper levels still work.
const childOptions =
options?.overrides?.enableFlatten === false ? undefined : options;
propRetValue =
`"${mapper.get(propName) ?? propName}": ` +
getParameterValue(context, propValue, options);
getParameterValue(context, propValue, childOptions);
}
if (propRetValue) values.push(propRetValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,112 @@ async function main(): Promise<void> {
await read();
}

main().catch(console.error);
```

# Independent multi-level flatten should work for sample input

When two flatten decorators are at different levels connected through a non-flatten property
(not consecutive/transition), the sample generator should apply both flattens independently.

## TypeSpec

This is tsp definition.

```tsp
model InnerContent {
state?: string;
scrubbingRules?: string;
}

model MiddleSettings {
@Azure.ClientGenerator.Core.Legacy.flattenProperty
innerContent?: InnerContent;
}

model OuterProperties {
settings?: MiddleSettings;
description?: string;
}

@doc("This is a simple model.")
model BodyParameter {
name: string;

@Azure.ClientGenerator.Core.Legacy.flattenProperty
properties: OuterProperties;
}

@doc("show example demo")
op read(@body body?: BodyParameter): void;

```

Enable the raw content with TCGC dependency.

```yaml
needArmTemplate: true
withVersionedApiVersion: true
needTCGC: true
```

## Example

Raw json files.

```json
{
"title": "read",
"operationId": "read",
"parameters": {
"body": {
"name": "test",
"properties": {
"settings": {
"innerContent": {
"state": "Enabled",
"scrubbingRules": "rule1"
}
},
"description": "a description"
}
}
},
"responses": {
"200": {}
}
}
```

## Samples

Generate sample with both flatten levels applied:

```ts samples
/** This file path is /samples-dev/readSample.ts */
import { TestingClient } from "@azure/internal-test";

/**
* This sample demonstrates how to show example demo
*
* @summary show example demo
* x-ms-original-file: 2021-10-01-preview/json.json
*/
async function read(): Promise<void> {
const endpoint = process.env.TESTING_ENDPOINT || "";
const client = new TestingClient(endpoint);
await client.read({
body: {
name: "test",
settings: { state: "Enabled", scrubbingRules: "rule1" },
description: "a description",
},
});
}

async function main(): Promise<void> {
await read();
}

main().catch(console.error);
```
Loading