encoding/jsonschema: use new definition mapping
This allows JSON Schema to now directly be compared to
data without qualifiers or remapping:
$ cue eval schema.json data.yaml
This works now more intuively as data and schema now map
one-to-one.
This relies on the change to allow `...` at the file level. This means
it is not necessary to use the new `isSchema` field. It seems
sensible to track this though and we may need it in the future.
One huge caveat of this new mapping is that it is now no longer
possible to have a non-struct schema with definitions remapped
to a different label. For this we need to allow embedded scalars in
structs. It still seems worth it and rather to allow this in the language.
Change-Id: I16988ca1c0d4436d591ba239964c4bb7445e6fd9
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5942
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
diff --git a/encoding/jsonschema/jsonschema.go b/encoding/jsonschema/jsonschema.go
index 4a59ab1..398cbbf 100644
--- a/encoding/jsonschema/jsonschema.go
+++ b/encoding/jsonschema/jsonschema.go
@@ -69,13 +69,14 @@
Root string
// Map maps the locations of schemas and definitions to a new location.
- // References are updated accordingly.
+ // References are updated accordingly. A returned label must be
+ // an identifier or string literal.
//
// The default mapping is
- // {} {"Schema"}
- // {"definitions", foo} {"Defs", strings.Title(foo)}
- // {"$defs", foo} {"Defs", strings.Title(foo)}
- Map func(pos token.Pos, path []string) ([]string, error)
+ // {} {}
+ // {"definitions", foo} {#foo} or {#def, foo}
+ // {"$defs", foo} {#foo} or {#def, foo}
+ Map func(pos token.Pos, path []string) ([]ast.Label, error)
// TODO: configurability to make it compatible with OpenAPI, such as
// - locations of definitions: #/components/schemas, for instance.