Class SchemaUnion
The base class for discriminated unions generated by Bonsai.Sgen.
A union can be defined by subclassing SchemaUnion and annotating its root field with
the member types, discriminated either by a constant tag declared by each member, through
Field(discriminator=...), or by tags assigned by the union, through DiscriminatedUnion.
The type name of the union follows the same rules as SchemaModel, and every member type
must be a SchemaModel. The generated code wraps any member type that is generated
elsewhere or belongs to another union.
Methods
View Sourcemodel_dump
Serializes the union to a dict, under aliases by default, including nested types.
Declaration
def model_dump(*, by_alias: bool | None = True, **kwargs: Any) -> Any
Parameters
| Type | Name | Description |
|---|---|---|
| bool | None | by_alias | |
| Any | **kwargs |
Returns
| Type | Description |
|---|---|
| Any |
model_dump_json
Serializes the union to JSON, under aliases by default, including nested types.
Declaration
def model_dump_json(*, by_alias: bool | None = True, **kwargs: Any) -> str
Parameters
| Type | Name | Description |
|---|---|---|
| bool | None | by_alias | |
| Any | **kwargs |
Returns
| Type | Description |
|---|---|
| str |