closedEnum function
Reads a closed-set string, where path already names the key.
An unrecognised value throws: a closed enum is not an extension point, so
falling back would place a control the client cannot honour (a sidebar
action read as row lands on every record). Absent yields ifAbsent, or
throws when the contract gives no default.
Implementation
String closedEnum(
Object? value,
Set<String> allowed,
String path, {
String? ifAbsent,
}) {
if (value == null && ifAbsent != null) return ifAbsent;
if (value is String && allowed.contains(value)) return value;
throw SchemaFormatException(
path,
'expected one of ${allowed.join(', ')}; got '
'${value is String ? '"$value"' : value.runtimeType}',
);
}