Skip to content

Commit

Permalink
internal/encoding: don't simplify interpreted encodings
Browse files Browse the repository at this point in the history
As this will cause file information to be lost.

The effect is relatively minor.

Change-Id: I25367088b202118ac16d24c3363f0c19553480a2
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6301
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: Johan Euphrosine <proppy@google.com>
  • Loading branch information
mpvl committed Jun 13, 2020
1 parent ddc8eb4 commit 519db58
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 0 additions & 2 deletions cmd/cue/cmd/testdata/script/def_jsonschema.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ age: twenty

-- expect-stderr2 --
age: conflicting values "twenty" and >=0 (mismatched types string and number):
14:7
./data.yaml:1:7
-- expect-stderr3 --
age: conflicting values "twenty" and >=0 (mismatched types string and number):
14:7
./data.yaml:1:7
-- cue.mod --
2 changes: 2 additions & 0 deletions cmd/cue/cmd/testdata/script/import_auto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cue import -o - ./openapi.yaml
cmp stdout expect-openapi

-- expect-openapi --


// An OpenAPI file

info: {
Expand Down
10 changes: 8 additions & 2 deletions internal/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,19 @@ func jsonSchemaFunc(cfg *Config, f *build.File) interpretFunc {

Strict: cfg.Strict,
}
file, err = simplify(jsonschema.Extract(i, cfg))
file, err = jsonschema.Extract(i, cfg)
// TODO: simplify currently erases file line info. Reintroduce after fix.
// file, err = simplify(file, err)
return file, id, err
}
}

func openAPIFunc(c *Config, f *build.File) interpretFunc {
cfg := &openapi.Config{PkgName: c.PkgName}
return func(i *cue.Instance) (file *ast.File, id string, err error) {
file, err = simplify(openapi.Extract(i, cfg))
file, err = openapi.Extract(i, cfg)
// TODO: simplify currently erases file line info. Reintroduce after fix.
// file, err = simplify(file, err)
return file, "", err
}
}
Expand Down Expand Up @@ -431,6 +435,8 @@ func simplify(f *ast.File, err error) (*ast.File, error) {
if err != nil {
return nil, err
}
// This needs to be a function that modifies f in order to maintain line
// number information.
b, err := format.Node(f, format.Simplify())
if err != nil {
return nil, err
Expand Down

0 comments on commit 519db58

Please sign in to comment.