Skip to content

if statement for external condition #3377

Answered by myitcv
gulnarrra asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @gulnarrra and welcome!

Yes, this is possible. But the identifier conf needs to be in scope in the CUE file.

Consider the following example:

# Good data
exec cue vet verifylist.cue good.json

# Bad data
! exec cue vet verifylist.cue bad.json
cmp stderr stderr.golden

-- verifylist.cue --
package verifylist

import "list"

// Assert that the data we validate against will contain a
// conf field with the given schema
conf!: {
	check_africa: bool
	ckeck_europe: bool
}

if conf.check_africa {
	("/tmp/africa.yml")?: structure!: conf!: cities!: list.Contains("Nairobi")
}

-- good.json --
{
  "/tmp/europe.yml": {
    "raw": "conf:\n  iscontinent: true\n  cities: [\"Dehli\", \"Paris\"]\n\n",
 …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gulnarrra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants