Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

vet sees exact values as optional fields #740

Closed
narqo opened this issue Feb 7, 2021 · 2 comments
Closed

vet sees exact values as optional fields #740

narqo opened this issue Feb 7, 2021 · 2 comments
Labels
roadmap/cli Specific tag for roadmap issue #337 roadmap/requiredfield Related to required fields proposal.
Milestone

Comments

@narqo
Copy link

narqo commented Feb 7, 2021

What version of CUE are you using (cue version)?

$ cue version
cue version 0.3.0-beta.4 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

Having a cue schema and a yaml data file:

$ cat schema.cue
env: [string]: #Env

#Env: {
    port: uint
    kafka_topic: "topic1" // field must exists and the value must be exactly "topic1"
}

$ cat data.yml
env:
  dev1:
    port: 8080
  dev2:
    port: 8080
    typo_topic: "topic1"
  dev3:
    port: 8080
    kafka_topic: "typo_topic1"
  dev4:
    port: 8080
    kafka_topic: "topic1"

Run cue vet to validate data.yml against the schema:

$ cue vet data.yml schema.cue

What did you expect to see?

I expect cue to report the following errors:

  • env.dev1 — missing required kafka_topic field,
  • env.dev2 — unexpected field typo_topic,
  • env.dev3 — conflicting value in kafka_topic field: got typo_topic1, want "topic1"

What did you see instead?

cue doesn't report the error about missing field in env.dev1. Only the errors in env.dev2 and env.dev3:

$ cue vet data.yml schema.cue                                                                                                                                                                         
env.dev2: field `typo_topic` not allowed:
    ./config1.cue:1:16
    ./config1.cue:3:7
    ./config1.yml:6:6
env.dev3.kafka_topic: conflicting values "topic1" and "typo_topic1":
    ./config1.cue:1:16
    ./config1.cue:5:18
    ./config1.yml:9:19

Note, in the example above, I could set the constraint for kafka_topic field via a RegExp =~"^topic1$". The issue is that the current behaviour of cue vet feels unintuitive.

@mpvl
Copy link
Contributor

mpvl commented Feb 7, 2021

There is currently no way in CUE to express that a field is required along with an exact concrete value. This is actually a high priority feature as is a blocker for various other extensions in CUE.

I hope to publish a proposal which addresses exactly the issues you are pointing out here, making constraint validation both more intuitive as well as get better error messages.

@mpvl mpvl added roadmap/cli Specific tag for roadmap issue #337 roadmap/requiredfield Related to required fields proposal. and removed NeedsInvestigation labels Feb 7, 2021
@myitcv myitcv added this to the v0.3.x milestone Mar 9, 2021
@cueckoo
Copy link

cueckoo commented Jul 3, 2021

This issue has been migrated to cue-lang/cue#740.

For more details about CUE's migration to a new home, please see cue-lang/cue#1078.

@cueckoo cueckoo closed this as completed Jul 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
roadmap/cli Specific tag for roadmap issue #337 roadmap/requiredfield Related to required fields proposal.
Projects
None yet
Development

No branches or pull requests

4 participants