Skip to content

Commit

Permalink
internal/encoding: allow CUE as OpenAPI input
Browse files Browse the repository at this point in the history
Regression.

Change-Id: I2c7b7e042da802a4f6c8017d83c494e96bbb1f6b
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5645
Reviewed-by: Marcel van Lohuizen <[email protected]>
  • Loading branch information
mpvl committed Apr 11, 2020
1 parent 83b0996 commit 8dcec3c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/cue/cmd/testdata/script/def_openapi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
...
}
7 changes: 7 additions & 0 deletions internal/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8dcec3c

Please sign in to comment.