Module adcp.types.validation

Validation helpers for public AdCP union aliases.

Functions

def validate_union(union: Any, payload: Any) ‑> Any
Expand source code
def validate_union(union: Any, payload: Any) -> Any:
    """Validate *payload* against a type or union, reusing its adapter.

    Pass an exported union alias such as ``WholesaleFeedEvent`` or
    ``VendorPricingOption``. Validation preserves the alias's discriminator
    and returns the selected model directly, without a ``RootModel`` wrapper.
    Invalid documents raise :class:`pydantic.ValidationError`.

    Adapters for hashable aliases are cached on first use in a bounded cache.
    An alias containing unhashable annotation metadata is also supported,
    using an uncached adapter.
    """
    try:
        hash(union)
    except TypeError:
        return TypeAdapter(union).validate_python(payload)
    return _union_adapter(union, id(union)).validate_python(payload)

Validate payload against a type or union, reusing its adapter.

Pass an exported union alias such as WholesaleFeedEvent or VendorPricingOption. Validation preserves the alias's discriminator and returns the selected model directly, without a RootModel wrapper. Invalid documents raise :class:pydantic.ValidationError.

Adapters for hashable aliases are cached on first use in a bounded cache. An alias containing unhashable annotation metadata is also supported, using an uncached adapter.