01 · Before and afterThe pattern
Scope the bypass by object type, and read flags positively.
// before: one switch disables "required" for every field type
if enforced() && isRequired(f) && isEmpty(v) { return errRequired(f) }
// after: only project fields follow the switch; others are always enforced
enforce := f.ObjectType != ObjectTypeProject || flags.ProjectFieldsRequired
if enforce && isRequired(f) && isEmpty(v) { return errRequired(f) }02 · Run it on your appThe check
When you add an “off switch” to a shared validator, is there a test proving that other record types are still validated with the switch on?
If the honest answer is no or not sure, this is worth a look before it reaches production.