diff --git a/encoding/jsonschema/constraints_array.go b/encoding/jsonschema/constraints_array.go index e72082b076e..daddb0118fe 100644 --- a/encoding/jsonschema/constraints_array.go +++ b/encoding/jsonschema/constraints_array.go @@ -40,11 +40,12 @@ func constraintAdditionalItems(key string, n cue.Value, s *state) { func constraintContains(key string, n cue.Value, s *state) { list := s.addImport(n, "list") - // TODO: Passing non-concrete values is not yet supported in CUE. - if x := s.schema(n); !isAny(x) { - x := ast.NewCall(ast.NewSel(list, "Contains"), clearPos(x)) - s.add(n, arrayType, x) - } + x := s.schema(n) + x = ast.NewCall(ast.NewSel(list, "MatchN"), &ast.UnaryExpr{ + Op: token.GEQ, + X: ast.NewLit(token.INT, "1"), + }, clearPos(x)) + s.add(n, arrayType, x) } func constraintItems(key string, n cue.Value, s *state) { diff --git a/encoding/jsonschema/testdata/contains.txtar b/encoding/jsonschema/testdata/contains.txtar new file mode 100644 index 00000000000..de637991052 --- /dev/null +++ b/encoding/jsonschema/testdata/contains.txtar @@ -0,0 +1,13 @@ +-- schema.yaml -- +type: object +properties: + p1: + type: array + contains: {} + +additionalProperties: false + +-- out/decode/extract -- +import "list" + +p1?: list.MatchN(>=1, _) diff --git a/encoding/jsonschema/testdata/list.txtar b/encoding/jsonschema/testdata/list.txtar index e8e79ae805d..07e7947851a 100644 --- a/encoding/jsonschema/testdata/list.txtar +++ b/encoding/jsonschema/testdata/list.txtar @@ -19,6 +19,11 @@ properties: contains: const: 3 + too: + type: array + contains: + type: string + size: type: array minItems: 3 @@ -40,7 +45,8 @@ import "list" foo?: [...string] tuple?: [string, int, 2] -has?: list.Contains(3) +has?: list.MatchN(>=1, 3) +too?: list.MatchN(>=1, string) size?: list.UniqueItems() & list.MaxItems(9) & [_, _, _, ...] additional?: [int, int, ...string] -- out/decode/testerr/err-foo-not-string --