Skip to content

Commit 5fdf0c2

Browse files
committed
encoding/jsonschema: define isTop and isBottom functions
In general, CUE does uses "top" rather than "all", and renaming `isAll` to `isTop` makes the corresponding `isBottom` function more obviously correspondent. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I93b172ca75e59415d60d14614f461a2a02ecc1eb Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1205768 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 9639ed8 commit 5fdf0c2

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

encoding/jsonschema/constraints_array.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ func constraintAdditionalItems(key string, n cue.Value, s *state) {
4545
panic("no elements in list")
4646
}
4747
last := s.list.Elts[len(s.list.Elts)-1].(*ast.Ellipsis)
48-
if _, isBottom := elem.(*ast.BottomLit); isBottom {
48+
if isBottom(elem) {
4949
// No additional elements allowed. Remove the ellipsis.
5050
s.list.Elts = s.list.Elts[:len(s.list.Elts)-1]
5151
return
5252
}
53-
if isAny(elem) {
53+
if isTop(elem) {
5454
// Nothing to do: there's already an ellipsis in place that
5555
// allows anything.
5656
return

encoding/jsonschema/constraints_object.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func constraintProperties(key string, n cue.Value, s *state) {
142142

143143
func constraintPropertyNames(key string, n cue.Value, s *state) {
144144
// [=~pattern]: _
145-
if names, _ := s.schemaState(n, cue.StringKind, nil); !isAny(names) {
145+
if names, _ := s.schemaState(n, cue.StringKind, nil); !isTop(names) {
146146
x := ast.NewStruct(ast.NewList(names), top())
147147
s.add(n, objectType, x)
148148
}

encoding/jsonschema/decode.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func (c *constraintInfo) setTypeUsed(n cue.Value, t coreType) {
378378
}
379379

380380
func (c *constraintInfo) add(n cue.Value, x ast.Expr) {
381-
if !isAny(x) {
381+
if !isTop(x) {
382382
setPos(x, n)
383383
ast.SetRelPos(x, token.NoRelPos)
384384
c.constraints = append(c.constraints, x)
@@ -948,11 +948,16 @@ func boolSchema(ok bool) ast.Expr {
948948
return bottom()
949949
}
950950

951-
func isAny(s ast.Expr) bool {
951+
func isTop(s ast.Expr) bool {
952952
i, ok := s.(*ast.Ident)
953953
return ok && i.Name == "_"
954954
}
955955

956+
func isBottom(e ast.Expr) bool {
957+
_, ok := e.(*ast.BottomLit)
958+
return ok
959+
}
960+
956961
func addTag(field ast.Label, tag, value string) *ast.Field {
957962
return &ast.Field{
958963
Label: field,

0 commit comments

Comments
 (0)