data dependency possibilities with CUE #2879
-
Hi, I am completely new to CUE and have an inquiry about data dependency possibilities. lets say that I have a data-dependency.cue file that is defined like this:
note: I know this is not valid syntax, but this is essentially what I want. The place should depend on the name given. and a schema.cue that is defined something like this:
and a data.yaml which we will test for validation based on the files above
this validation should fail because Alice doesn't have Chicago as one of her #place. How would I do something like this in cue or go. Note that data-dependency.cue values can change, but #name and #place remain the same and it is something the user will manually define. I understand there are conditional fields but does it work with dynamic data-dependency files? Thank you for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
There are a few different ways to achieve this! Here's a playground link that combines 2 methods in 1 evaluation: https://alpha.cuelang.org/play/?id=tIne24zL-Lv#w=function&i=cue&f=eval&o=cue. The method you use (and there are definitely more methods!) is down to your preference. Notice that on line 23, both The playground isn't showing the errors with Bob's failing example. I believe this is a CUE Playground artifact - if you were to comment out Alice's failing example, the Bob failure would still strike. |
Beta Was this translation helpful? Give feedback.
There are a few different ways to achieve this! Here's a playground link that combines 2 methods in 1 evaluation: https://alpha.cuelang.org/play/?id=tIne24zL-Lv#w=function&i=cue&f=eval&o=cue. The method you use (and there are definitely more methods!) is down to your preference.
Notice that on line 23, both
#Sample1
and#Sample2
are unified, which is only possible because they can unify successfully, and they both represent the same constraints. You shouldn't use both methods simultaneously - I'm just demonstrating that both achieve the same outcome.The playground isn't showing the errors with Bob's failing example. I believe this is a CUE Playground artifact - if you were to comment out…