Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/jsonschema: nested definitions with the same name are not referred to correctly #3593

Open
rogpeppe opened this issue Nov 26, 2024 · 0 comments

Comments

@rogpeppe
Copy link
Member

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

$ cue version
v0.11.0

Does this issue reproduce with the latest stable release?

Yes (v0.11.0)

What did you do?

exec cue import schema.json
exec cat schema.cue
exec cue vet schema.cue data.json

-- data.json --
["a", "b", "c", "d"]
-- schema.json --
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$defs": {
        "bar": {
            "type": "string"
        },
        "foo": {
            "items": {
                "$defs": {
                    "bar": {
                        "type": "number"
                    }
                },
                "$ref": "#/$defs/bar"
            },
            "minLength": 4,
            "type": "array"
        }
    },
    "$ref": "#/$defs/foo"
}

What did you expect to see?

A passing test. The $ref refers to the top level bar definition (type string)
not the inner bar definition (type number) but the reference is not encoded correctly.

What did you see instead?

> exec cue import schema.json
> exec cat schema.cue
[stdout]
@jsonschema(schema="https://json-schema.org/draft/2020-12/schema")
#foo

#bar: string

#foo: [...{
	#bar

	#bar: number
}]
> exec cue vet schema.cue data.json
[stderr]
0: conflicting values "a" and number (mismatched types string and number):
    ./data.json:1:2
    ./schema.cue:2:1
    ./schema.cue:6:8
    ./schema.cue:7:2
    ./schema.cue:9:8
1: conflicting values "b" and number (mismatched types string and number):
    ./data.json:1:7
    ./schema.cue:2:1
    ./schema.cue:6:8
    ./schema.cue:7:2
    ./schema.cue:9:8
2: conflicting values "c" and number (mismatched types string and number):
    ./data.json:1:12
    ./schema.cue:2:1
    ./schema.cue:6:8
    ./schema.cue:7:2
    ./schema.cue:9:8
3: conflicting values "d" and number (mismatched types string and number):
    ./data.json:1:17
    ./schema.cue:2:1
    ./schema.cue:6:8
    ./schema.cue:7:2
    ./schema.cue:9:8
[exit status 1]
FAIL: /tmp/z.txtar:3: unexpected command failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant