encoding/jsonschema: expose API of JSON Schema decoder
Change-Id: I191d7bc2394486fa63050fca6721f65aa0589b22
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4760
Reviewed-by: Antoine Pelisse <apelisse@google.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/encoding/jsonschema/decode.go b/encoding/jsonschema/decode.go
index 84d7ed8..c644ff0 100644
--- a/encoding/jsonschema/decode.go
+++ b/encoding/jsonschema/decode.go
@@ -34,19 +34,10 @@
const rootDefs = "def"
-func decode(filename string, inst *cue.Instance) (*ast.File, errors.Error) {
- d := &decoder{
- imports: map[string]*ast.Ident{},
- }
- e := d.decode(filename, inst)
- if d.errs != nil {
- return nil, d.errs
- }
- return e, nil
-}
-
// A decoder converts JSON schema to CUE.
type decoder struct {
+ cfg *Config
+
errs errors.Error
imports map[string]*ast.Ident
@@ -63,12 +54,13 @@
return ident
}
-func (d *decoder) decode(filename string, inst *cue.Instance) *ast.File {
+func (d *decoder) decode(inst *cue.Instance) *ast.File {
root := state{decoder: d}
expr, state := root.schemaState(inst.Value())
var a []ast.Decl
+ filename := d.cfg.ID
name := filepath.ToSlash(filename)
if state.id != "" {
name = strings.Trim(name, "#")