Validators



A pattern for validating other fields with an additional field.

check-port.cue

import "strconv"

#portI: uint16 & >1024

#portS: S={
	string & =~"^[0-9]{4,5}$"
	_i:     strconv.Atoi(S)
	#valid: uint16 & >1024 & _i
}

#port: #portI | #portS

pi: #port
pi: 8080

ps: #portS
ps: "1313"

cue eval check-port.cue

pi: 8080
ps: "1313"

GitHub comment introducing the syntax for this validator: https://github.com/cue-lang/cue/issues/620#issuecomment-873390016

We'll never share your email with anyone else.
2022 Hofstadter, Inc