Validate conditional fields #706
-
I have a list of structs. Dependent on the value of one field the structs have different other fields. For example here is a yml file with two persons. Minors need someone responsible: ---
person1:
name: Bob
age: 35
person2:
name: Bill
age: 12
responsible: Anna I am trying to validate this with this schema: person1: #Person
person2: #Person
#Person: {
name: string
age: int
if age < 18 {
responsible: string
}
} But It seems, that conditional fields only work with Is there a way to conditionally validate a struct? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
You can open a definition struct using
However, that means data or other types that refer to I'm fairly new to CUE, but I believe the conventional approach is:
This evaluates to:
|
Beta Was this translation helpful? Give feedback.
-
Please can you give a bit more detail on what you tried originally (including CUE version)? Because it does/should work:
Run with CUE version ed8bdaf which might be relevant. |
Beta Was this translation helpful? Give feedback.
-
This discussion has been migrated to cue-lang/cue#706. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
Beta Was this translation helpful? Give feedback.
You can open a definition struct using
...
, such as:However, that means data or other types that refer to
#Person
are now open ended to accept any other fields, which is often not desired.I'm fairly new to CUE, but I believe the conventional approach is:
This evaluates to: