Commit c571c68
Honor x-ms-client-flatten in Bicep type generator (#12001)
# Description
Implements
[`x-ms-client-flatten`](https://github.com/Azure/autorest/tree/main/docs/extensions#x-ms-client-flatten)
in the Radius Bicep type generator so the ARM `.properties.` envelope no
longer leaks into user-authored Bicep templates.
Before:
```bicep
container.properties.container.image
gateway.properties.url
```
After:
```bicep
container.container.image
gateway.url
```
The annotation is already present on every Radius resource (via
`TrackedResourceRequired` in `typespec/radius/v1/trackedresource.tsp`);
the generator just had not been honoring it.
## Type of change
- This pull request adds or changes features of Radius and has an
approved issue (issue link required).
Fixes: #12000
# Contributor checklist
- [x] Existing tests pass
- [x] New tests added (unit + integration + functional)
- [x] Generated artifacts refreshed
- [N/A] Schema/typespec changes — annotation already existed
- [N/A] Sample/doc Bicep rewrites — deferred to a follow-up; this PR is
backward compatible
# Changes
## Generator (`hack/bicep-types-radius/src/autorest.bicep`)
- `src/type-generator.ts`
- New helpers: `isFlattenSafe`, `flagsForFlattenedChild`,
`expandFlattenedInto`.
- Wire flattening into both `processResourceBody` (resource envelope)
and `parseObjectType` (nested objects).
- Fall back to the nested representation (with a warning via
`logWarning`) when flattening would lose information:
- The schema uses a discriminator (polymorphic variants).
- A flattened child name collides with an existing parent property.
- Each flattened child is emitted as `ReadOnly`. `Required`,
`WriteOnly`, `Identifier`, and `DeployTimeConstant` are intentionally
not propagated from the wrapper — the flat alias is unambiguously a
read-side projection of the underlying `properties` payload.
## Tests
- `test/integration/specs/basic/.../spec.json` — extended with:
- `TestType1` — happy-path flatten on a resource body.
- `TestType2` — polymorphic child, exercises the discriminator fallback.
- `TestType3` — child property names collide with the resource envelope,
exercises the collision fallback.
- Checked-in baselines (`test/integration/generated/basic/...`)
refreshed.
- New programmatic Jest suite `test/flatten/flatten.test.ts` asserts the
contract end-to-end: walks the generated `types.json` and verifies
hoisting, fallback emission, and warning behavior.
## Regenerated Bicep types
Ran `make generate-bicep-types`. Updated:
-
`hack/bicep-types-radius/generated/applications/applications.core/2023-10-01-preview/types.json`
-
`hack/bicep-types-radius/generated/applications/applications.datastores/2023-10-01-preview/types.json`
-
`hack/bicep-types-radius/generated/applications/applications.messaging/2023-10-01-preview/types.json`
-
`hack/bicep-types-radius/generated/radius/radius.core/2025-08-01-preview/types.json`
- `hack/bicep-types-radius/generated/index.json`
Spot-checked: e.g. `Applications.Core/containers` now exposes
`application`, `container`, `connections`, `extensions`, `environment`,
`identity`, `restartPolicy`, `runtimes`, `resources`,
`provisioningState`, `status` directly on the resource body, with no
`ApplicationProperties` / `ContainerProperties` wrapper.
## Functional test
`test/functional-portable/corerp/noncloud/resources/container_flatten_test.go`
+ `testdata/corerp-resources-container-flatten.bicep` —
`Test_Container_Flatten` deploys an Application + Container written
entirely in the flat syntax (no `.properties.`) and validates the RP
resources and the rendered pod in the app namespace. The bicep template
only compiles against the regenerated types, so the test doubles as a
regression guard.
# Compatibility
- Flattening is purely **additive and read-side only**. The wrapper
`properties: { ... }` is preserved as the writable authoring surface —
existing templates that author via `.properties.{ ... }` continue to
work unchanged. Hoisted flat aliases are emitted with the `ReadOnly`
flag, so they can be consumed via `reference('foo').bar` / `output x =
foo.bar` but cannot be assigned from a template body. This is
intentional: it eliminates `.properties.` from read-side expressions
without requiring any breaking authoring-side change.
- Existing sample/doc/test Bicep files in this repo are NOT rewritten in
this PR; that is a deliberately scoped follow-up.
# Deployment-engine dependency (resolved)
The deploy-time half of this feature shipped in
[azure-octo/deployment-engine#583](azure-octo/deployment-engine#583)
(merged), which flattens the JToken stored in the reference value lookup
so flat references like `reference('myCtnr').application` resolve at
deploy time. The `:latest` `ghcr.io/radius-project/deployment-engine`
image picks up the fix automatically.
Validated end-to-end on a local kind cluster prior to merge:
`Test_Container_Flatten` passes.
---------
Signed-off-by: willdavsmith <willdavsmith@gmail.com>
Co-authored-by: Dariusz Porowski <3431813+DariuszPorowski@users.noreply.github.com>1 parent c43a316 commit c571c68
15 files changed
Lines changed: 4299 additions & 1241 deletions
File tree
- hack/bicep-types-radius
- generated
- applications
- applications.core/2023-10-01-preview
- applications.datastores/2023-10-01-preview
- applications.messaging/2023-10-01-preview
- radius/radius.core/2025-08-01-preview
- src/autorest.bicep
- src
- test
- flatten
- integration
- generated/basic/test.rp1/2021-10-31
- docs
- specs/basic/resource-manager/Test.Rp1/stable/2021-10-31
- test/functional-portable/corerp/noncloud/resources
- testdata
Lines changed: 1292 additions & 596 deletions
Large diffs are not rendered by default.
Lines changed: 735 additions & 225 deletions
Large diffs are not rendered by default.
Lines changed: 270 additions & 86 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
0 commit comments