cue icon indicating copy to clipboard operation
cue copied to clipboard

encoding/jsonschema: incorrect encoding of "items" keyword

Open rogpeppe opened this issue 1 year ago • 0 comments

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

2d4a8952a5e7c8b8c4815ed89741c52e343cd17e

Does this issue reproduce with the latest stable release?

Yes (v0.10.0)

What did you do?

What did you expect to see?

A passing test. The spec says this:

If "items" is an array of schemas, validation succeeds if each element of the instance validates against the schema at the same position, if any. That means that the above JSON schema should be considered valid against not only ["a", "b", "c"] but also ["a", "b", "c", true] (the list should be open) and also [], ["a"] and ["a", "b"] (any prefix of the "items" array can match).

What did you see instead?

> exec cue def -l '#S:' -p main -o schema.cue schema.json
> exec cat schema.cue
[stdout]
package main

#S: {
	@jsonschema(schema="https://json-schema.org/draft/2019-09/schema")
	["a", "b", "c"]
}
> exec cue vet
[stderr]
tests.0: incompatible list lengths (0 and 3)
tests.1: incompatible list lengths (1 and 3)
tests.2: incompatible list lengths (2 and 3)
tests.4: incompatible list lengths (3 and 4)
[exit status 1]
FAIL: x.txtar:3: unexpected command failure

Currently there is no nice way to encode this kind of constraint. The query proposal (#165) might help here (see specifically the "Integers in label expressions" section in that issue).

rogpeppe avatar Oct 09 '24 10:10 rogpeppe