cue icon indicating copy to clipboard operation
cue copied to clipboard

encoding/jsonschema: doc comments are lost

Open rogpeppe opened this issue 1 year ago • 0 comments

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

6e0525b34633e296ae3e775faf7e4e99456c33e4

Does this issue reproduce with the latest stable release?

Yes (v0.10.0)

What did you do?

exec cue def -l '#top:' schema.json
stdout 'description of a field'
stdout 'overall description'
stdout 'description of foo'

-- schema.json --
{
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "$defs": {
        "foo": {
            "description": "description of foo",
            "properties": {
                "a": {
                    "description": "description of a field",
                    "type": "number"
                }
            }
        }
    },
    "description": "overall description",
    "$ref": "#/$defs/foo"
}

What did you expect to see?

A passing test. All the descriptions should be present as doc comments in the result.

What did you see instead?

> exec cue def -l '#top:' schema.json
[stdout]
#top: {
	// overall description
	@jsonschema(schema="https://json-schema.org/draft/2019-09/schema")
	#foo
	#foo: null | bool | number | string | [...] | {
		// description of a field
		a?: number
		...
	}
}
> stdout 'description of a field'
> stdout 'overall description'
> stdout 'description of foo'
FAIL: y.txtar:4: no match for `description of foo` found in stdout

The description of the foo definition isn't present, and the "overall description" text has moved into an inner comment on #top, where it will then be lost when computed with (e.g. compiling to a cue.Value) because it doesn't attach to any particular field.

rogpeppe avatar Oct 18 '24 15:10 rogpeppe