-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/core/adt: allow referencing required fields
This is intended to be a temporary measure to help the transition of JSON schema to use ! for required properties. Currently, CUE code that relied on the JSON schema generator to generate regular fields for required fields could just reference those fields. This code is currently broken by this transition. In practice, however, there does not seem to be much harm in allowing reference to refer to required fields. CUE allows errors to be elided if another error is guaranteed to be given otherwise. This is not always the case, but but it seems that this is fine for any practical purpose. Example where this is fully okay: #Foo: { a!: 1 b: a } // c currently has errors for c.a (required field missing) and // c.b (referencing required field). With this change, the // second error is removed. But since there is still an error // for the underlying problem (a missing required field), this // is okay. c: #Foo If, on the other hand, we would write: c: #Foo.a then `c` will not produce an error where before this change it would. Note that, for export at least, this is only true if a required field is used in combination with a fully concrete value. We also think this solution does not complicate finding a more principled solution later. If the JSON Schema change is left in, users will be forced to adjust their code as is. To facilitate such transition, we would have to write a `cue fix`. This same mechansim could later be used to move code that references required fields to using some alternative. This CL allows for a smoother transition either way. Note that there was a discrepancy in the semantics between v2 and v3 that has been removed by this change. Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com> Change-Id: I6b79bcc858ea7c2a76418b58e6ef22839c558df2 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199898 TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
- Loading branch information
Showing
3 changed files
with
33 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters