Background
Follow-up from #3917 / #3928 / #3934. The outer oneOf at `core/format.json` `#/properties/assets/items` (15 variants) cannot be cleanly discriminated by a single key today.
- Variants 0–13 (`Individual{Image,Video,Audio,...}Asset`) declare `item_type: "individual"` and `asset_type: ""`
- Variant 14 (`RepeatableGroupAsset`) declares `item_type: "repeatable_group"` and has no `asset_type`
Adding `discriminator.propertyName="asset_type"` fails because variant 14 doesn't have it. Adding `discriminator.propertyName="item_type"` doesn't help downstream codegen because 14 of the 15 variants share the same `item_type` value.
Proposed restructure
Split the union into two tiers:
```json
{
"discriminator": { "propertyName": "item_type" },
"oneOf": [
{
"properties": { "item_type": { "const": "individual" } },
"required": ["item_type"],
"discriminator": { "propertyName": "asset_type" },
"oneOf": [ ...14 individual variants... ]
},
{
"properties": { "item_type": { "const": "repeatable_group" } },
"required": ["item_type"],
// RepeatableGroupAsset shape
}
]
}
```
This produces a TypeScript codegen output along the lines of:
```ts
type Item =
| (IndividualAssetCommon & ({ asset_type: 'image'; ... } | { asset_type: 'video'; ... } | ...))
| RepeatableGroupAsset;
```
instead of today's flat 15-way structurally-overlapping union.
Acceptance
Refs
Background
Follow-up from #3917 / #3928 / #3934. The outer oneOf at `core/format.json` `#/properties/assets/items` (15 variants) cannot be cleanly discriminated by a single key today.
Adding `discriminator.propertyName="asset_type"` fails because variant 14 doesn't have it. Adding `discriminator.propertyName="item_type"` doesn't help downstream codegen because 14 of the 15 variants share the same `item_type` value.
Proposed restructure
Split the union into two tiers:
```json
{
"discriminator": { "propertyName": "item_type" },
"oneOf": [
{
"properties": { "item_type": { "const": "individual" } },
"required": ["item_type"],
"discriminator": { "propertyName": "asset_type" },
"oneOf": [ ...14 individual variants... ]
},
{
"properties": { "item_type": { "const": "repeatable_group" } },
"required": ["item_type"],
// RepeatableGroupAsset shape
}
]
}
```
This produces a TypeScript codegen output along the lines of:
```ts
type Item =
| (IndividualAssetCommon & ({ asset_type: 'image'; ... } | { asset_type: 'video'; ... } | ...))
| RepeatableGroupAsset;
```
instead of today's flat 15-way structurally-overlapping union.
Acceptance
Refs