Skip to content

Commit 93ea8c6

Browse files
committed
Add untagged variant to the modelling guide
1 parent 701f55d commit 93ea8c6

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

docs/modeling-guide.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ An annotation allows distinguishing these properties from container variants:
418418

419419
For example:
420420

421-
```
421+
```ts
422422
/**
423423
* @variants container
424424
*/
@@ -435,6 +435,38 @@ class AggregationContainer {
435435
...
436436
```
437437
438+
#### Untagged
439+
440+
The untagged variant is used for unions that can only be distinguished by the type of one or more fields.
441+
442+
> [!WARNING]
443+
> 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.
444+
445+
The syntax is:
446+
447+
```ts
448+
/** @variants untagged */
449+
```
450+
451+
Untagged variants must exactly follow a defined pattern.
452+
453+
For example:
454+
455+
```ts
456+
export class MyTypeBase<T1, T2, ...> { ... }
457+
458+
export class MyTypeSpecialized1 extends MyTypeBase<int> {}
459+
export class MyTypeSpecialized2 extends MyTypeBase<string> {}
460+
export class MyTypeSpecialized3 extends MyTypeBase<bool> {}
461+
462+
/**
463+
* @codegen_names mytype1, mytypet2, mytype3
464+
* @variant untagged
465+
*/
466+
// Note: deserialization depends on value types
467+
export type MyType = MyTypeSpecialized1 | MyTypeSpecialized2 | MyTypeSpecialized3
468+
```
469+
438470
### Shortcut properties
439471
440472
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.

0 commit comments

Comments
 (0)