Skip to content

0.14.0-beta1 Enable Inline Discriminators

Pre-release
Pre-release
Compare
Choose a tag to compare
@mfleader mfleader released this 11 Apr 18:41
· 10 commits to main since this release

Adds a boolean attribute, discriminator_inlined, to OneOfStringType and OneOfIntType describing whether or not the discriminator field name is embedded inline with the schemas of the underlying types (the union's constituent/member types).

import dataclasses
import typing

from arcaflow_plugin_sdk import schema


@dataclasses.dataclass
class InlineInt:
    type_: int
    msg: str


@dataclasses.dataclass
class InlineInt2:
    type_: int
    msg2: str


@dataclasses.dataclass
class TestData:
    union: typing.Annotated[
        typing.Union[
            typing.Annotated[InlineInt, schema.discriminator_value(1)],
            typing.Annotated[
                InlineInt2, schema.discriminator_value(2)
            ],
        ],
        schema.discriminator(
           discriminator_field_name="type_",
           discriminator_inlined=True
        ),
    ]