Skip to content

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

@rogpeppe

Description

@rogpeppe

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions