diff --git a/docs/modeling-guide.md b/docs/modeling-guide.md index d2a1b78b94..fab7329982 100644 --- a/docs/modeling-guide.md +++ b/docs/modeling-guide.md @@ -418,7 +418,7 @@ An annotation allows distinguishing these properties from container variants: For example: -``` +```ts /** * @variants container */ @@ -435,6 +435,38 @@ class AggregationContainer { ... ``` +#### Untagged + +The untagged variant is used for unions that can only be distinguished by the type of one or more fields. + +> [!WARNING] +> This variant should only be used for legacy types and should otherwise be avoided as far as possible, as it leads to less optimal code generation in the client libraries. + +The syntax is: + +```ts +/** @variants untagged */ +``` + +Untagged variants must exactly follow a defined pattern. + +For example: + +```ts +export class MyTypeBase { ... } + +export class MyTypeSpecialized1 extends MyTypeBase {} +export class MyTypeSpecialized2 extends MyTypeBase {} +export class MyTypeSpecialized3 extends MyTypeBase {} + +/** + * @codegen_names mytype1, mytypet2, mytype3 + * @variant untagged + */ +// Note: deserialization depends on value types +export type MyType = MyTypeSpecialized1 | MyTypeSpecialized2 | MyTypeSpecialized3 +``` + ### Shortcut properties In many places Elasticsearch accepts a property value to be either a complete data structure or a single value, that value being a shortcut for a property in the data structure.