flatten-polymorphism
@azure-tools/typespec-client-generator-core/flatten-polymorphismSeverity: error
This diagnostic is issued when @flattenProperty is applied to a model property whose type is polymorphic (a discriminated type). Flattening a polymorphic type is not supported, because most languages cannot represent it.
Impact
Section titled “Impact”- Area: SDK model flattening. Blocks applying
@flattenPropertybecause flattening a discriminated model would break generated polymorphic model structure. - Not affected: The discriminator and inheritance described by the service model remain unchanged.
❌ Incorrect Usage
Section titled “❌ Incorrect Usage”@discriminator("kind")model Pet { kind: string;}model Cat extends Pet { kind: "cat";}
model Owner { @flattenProperty // `pet` has polymorphic type `Pet` pet: Pet;}Diagnostic Message
Section titled “Diagnostic Message”TCGC reports:
Cannot flatten property of polymorphic type.✅ How to Fix
Section titled “✅ How to Fix”Remove @flattenProperty from the polymorphic property, or change the property to a non-polymorphic type.
@discriminator("kind")model Pet { kind: string;}model Cat extends Pet { kind: "cat";}
model Owner { pet: Pet;}