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.06k stars 288 forks source link

encoding/jsonschema: additionalProperties false in top level object results in open struct #3381

Open rogpeppe opened 1 month ago

rogpeppe commented 1 month ago

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

$ cue version
v0.10.0

Does this issue reproduce with the latest stable release?

Yes

What did you do?

exec cue def schema.json
cmp stdout want-stdout

-- want-stdout --
@jsonschema(schema="https://json-schema.org/draft/2020-12/schema")

_#: {}
_#
-- schema.json --
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "additionalProperties": false
}

What did you expect to see?

A passing test (or similar closed struct output)

What did you see instead?

> exec cue def schema.json
[stdout]
@jsonschema(schema="https://json-schema.org/draft/2020-12/schema")
...
> cmp stdout want-stdout
diff stdout want-stdout
--- stdout
+++ want-stdout
@@ -1,2 +1,4 @@
 @jsonschema(schema="https://json-schema.org/draft/2020-12/schema")
-...
+
+_#: {}
+_#

FAIL: /tmp/testscript2715937007/x.txtar/script.txtar:2: stdout and want-stdout differ

The resulting top level struct is not closed as it should be.

myitcv commented 1 month ago

The resulting top level struct is not closed as it should be.

I think it probably depends on how the result is used. If the imported result is used as a package value, then it is closed.

What's your intuition on what we should do here?

This is very much related to https://github.com/cue-lang/cue/issues/3008