cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.15k stars 297 forks source link

encoding/jsonschema: schema is sensitive to field ordering of `items` vs `additionalItems` #3544

Closed rogpeppe closed 3 weeks ago

rogpeppe commented 4 weeks ago

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

73d4e2559fb69d798244e4ada3f1d52704e92d30

Does this issue reproduce with the latest stable release?

Yes

What did you do?

exec cue def schema1.json
cmp stdout want-stdout

exec cue def schema2.json
cmp stdout want-stdout
-- want-stdout --
@jsonschema(schema="http://json-schema.org/draft-07/schema#")
["foo", ...]
-- schema1.json --
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "array",
    "items": [
        {
            "const": "foo"
        }
    ],
    "additionalItems": {}
}
-- schema2.json --
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "array",
    "additionalItems": {},
    "items": [
        {
            "const": "foo"
        }
    ]
}

What did you expect to see?

A passing test. The only way that schema1.json and schema2.json differ is in the ordering of items and additionalItems fields. The output should be the same regardless of their respective order.

What did you see instead?

> exec cue def schema1.json
[stdout]
@jsonschema(schema="http://json-schema.org/draft-07/schema#")
["foo", ...]
> cmp stdout want-stdout
> exec cue def schema2.json
[stdout]
@jsonschema(schema="http://json-schema.org/draft-07/schema#")
["foo"]
> cmp stdout want-stdout
diff stdout want-stdout
--- stdout
+++ want-stdout
@@ -1,2 +1,2 @@
 @jsonschema(schema="http://json-schema.org/draft-07/schema#")
-["foo"]
+["foo", ...]

FAIL: /tmp/x.txtar:5: stdout and want-stdout differ