class BiDiGenerate::Schema

def union_from_selector(name, selector)

grouping, never domain-scoped, so it is never emitted as a class.
dispatch. Unreachable here: every correlated union is a top-level result
{ correlated: true } -> resolved by request id, not the payload, so no payload
{ ordered: [{ ref, requires }] } -> presence rules in the spec's choice order.
as the fallback (it may itself be a union, which finishes the dispatch).
{ by, variants, default? } -> a discriminator table (value => ref), `default`
Map a union `selector` to dispatch variants the template renders:
def union_from_selector(name, selector)
  # A correlated union is resolved by request id, never the payload, so it carries
  # no dispatch — it must never be emitted (every one is a top-level result
  # grouping). Fail loudly if a future schema makes one domain-scoped rather than
  # emit a Union whose every parse would raise.
  if selector['correlated']
    raise "correlated union #{name} must not be emitted (resolved by request id, not payload)"
  end
  variants = selector['by'] ? discriminated_variants(selector) : ordered_variants(selector)
  raise "union #{name} selector yielded no dispatch variants" if variants.empty?
  UnionClass.new(ruby_name: BiDiGenerate.type_class_name(name),
                 discriminator_wire: selector['by'], variants: variants, schema_name: name)
end