diff --git a/cmd/cue/cmd/testdata/script/def_openapi.txt b/cmd/cue/cmd/testdata/script/def_openapi.txt index 76a46f6ae52..892d4498ee8 100644 --- a/cmd/cue/cmd/testdata/script/def_openapi.txt +++ b/cmd/cue/cmd/testdata/script/def_openapi.txt @@ -14,6 +14,10 @@ cmp stdout expect-cue cue def -p foo openapi.json cmp stdout expect-cue +# cue to openapi +cue def openapi+cue: expect-cue-out -o - +cmp stdout expect-cue2 + -- foo.cue -- // Some clever title. @@ -181,3 +185,17 @@ Foo :: { b: >=0 & <10 ... } +-- expect-cue2 -- +info: { + title: "Some clever title." + version: "v1" +} +Bar :: { + foo: Foo + ... +} +Foo :: { + a: int + b: >=0 & <10 + ... +} diff --git a/internal/encoding/encoding.go b/internal/encoding/encoding.go index 0a0b07cd60c..5b4a73338d2 100644 --- a/internal/encoding/encoding.go +++ b/internal/encoding/encoding.go @@ -78,6 +78,10 @@ func (i *Decoder) Next() { if i.err != nil { return } + i.doInterpret() +} + +func (i *Decoder) doInterpret() { // Interpretations if i.interpret != nil { var r cue.Runtime @@ -197,6 +201,9 @@ func NewDecoder(f *build.File, cfg *Config) *Decoder { i.file, i.err = cfg.ParseFile(path, r) } i.validate(i.file, f) + if i.err == nil { + i.doInterpret() + } case build.JSON, build.JSONL: i.next = json.NewDecoder(nil, path, r).Extract i.Next()