-
-
Notifications
You must be signed in to change notification settings - Fork 963
Closed
Description
Based on #656 a custom unmarshal function can be defined on enum types to validate that the provided enum value is actually allowed by the spec. The generated code could look as follows:
func (v *Status) UnmarshalJSON(bs []byte) error {
var s string
if err := json.Unmarshal(bs, &s); err != nil {
return err
}
switch Status(s) {
case StatusSuccess, StatusFailed:
*v = Status(s)
return nil
default:
return fmt.Errorf("invalid enum value %q", s)
}
}
Metadata
Metadata
Assignees
Labels
No labels