From 15731c3a97734f46e61dcd7046897841afad3585 Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Mon, 9 Sep 2024 14:47:39 +0100 Subject: [PATCH] internal/encoding: remove Decoder.ID method This method is not used by anything inside CUE, only applies to JSON Schema (and that not very well) and does not seem worth keeping around in general. Signed-off-by: Roger Peppe Change-Id: Iab491b2faee65cd33a365ce67377ee1e5cfcbb0e Dispatch-Trailer: {"type":"trybot","CL":1200898,"patchset":2,"ref":"refs/changes/98/1200898/2","targetBranch":"master"} --- internal/encoding/encoding.go | 37 ++++++++--------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/internal/encoding/encoding.go b/internal/encoding/encoding.go index 6f62ded48..9ae4dc901 100644 --- a/internal/encoding/encoding.go +++ b/internal/encoding/encoding.go @@ -20,8 +20,6 @@ package encoding import ( "fmt" "io" - "net/url" - "strings" "cuelang.org/go/cue" "cuelang.org/go/cue/ast" @@ -57,19 +55,13 @@ type Decoder struct { expr ast.Expr file *ast.File filename string // may change on iteration for some formats - id string index int err error } -type interpretFunc func(cue.Value) (file *ast.File, id string, err error) +type interpretFunc func(cue.Value) (file *ast.File, err error) type rewriteFunc func(*ast.File) (file *ast.File, err error) -// ID returns a canonical identifier for the decoded object or "" if no such -// identifier could be found. -func (i *Decoder) ID() string { - return i.id -} func (i *Decoder) Filename() string { return i.filename } // Interpretation returns the current interpretation detected by Detect. @@ -110,7 +102,7 @@ func (i *Decoder) doInterpret() { i.err = err return } - i.file, i.id, i.err = i.interpretFunc(v) + i.file, i.err = i.interpretFunc(v) } } @@ -206,14 +198,14 @@ func NewDecoder(ctx *cue.Context, f *build.File, cfg *Config) *Decoder { case build.Auto: openAPI := openAPIFunc(cfg, f) jsonSchema := jsonSchemaFunc(cfg, f) - i.interpretFunc = func(v cue.Value) (file *ast.File, id string, err error) { + i.interpretFunc = func(v cue.Value) (file *ast.File, err error) { switch i.interpretation = Detect(v); i.interpretation { case build.JSONSchema: return jsonSchema(v) case build.OpenAPI: return openAPI(v) } - return i.file, "", i.err + return i.file, i.err } case build.OpenAPI: i.interpretation = build.OpenAPI @@ -291,21 +283,8 @@ func NewDecoder(ctx *cue.Context, f *build.File, cfg *Config) *Decoder { } func jsonSchemaFunc(cfg *Config, f *build.File) interpretFunc { - return func(v cue.Value) (file *ast.File, id string, err error) { - id = f.Tags["id"] - if id == "" { - id, _ = v.LookupPath(cue.MakePath(cue.Str("$id"))).String() - } - if id != "" { - u, err := url.Parse(id) - if err != nil { - return nil, "", errors.Wrapf(err, token.NoPos, "invalid id") - } - u.Scheme = "" - id = strings.TrimPrefix(u.String(), "//") - } + return func(v cue.Value) (file *ast.File, err error) { cfg := &jsonschema.Config{ - ID: id, PkgName: cfg.PkgName, Strict: cfg.Strict, @@ -313,17 +292,17 @@ func jsonSchemaFunc(cfg *Config, f *build.File) interpretFunc { file, err = jsonschema.Extract(v, cfg) // TODO: simplify currently erases file line info. Reintroduce after fix. // file, err = simplify(file, err) - return file, id, err + return file, err } } func openAPIFunc(c *Config, f *build.File) interpretFunc { cfg := &openapi.Config{PkgName: c.PkgName} - return func(v cue.Value) (file *ast.File, id string, err error) { + return func(v cue.Value) (file *ast.File, err error) { file, err = openapi.Extract(v, cfg) // TODO: simplify currently erases file line info. Reintroduce after fix. // file, err = simplify(file, err) - return file, "", err + return file, err } }