Skip to content

Commit 8dcec3c

Browse files
committed
internal/encoding: allow CUE as OpenAPI input
Regression. Change-Id: I2c7b7e042da802a4f6c8017d83c494e96bbb1f6b Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5645 Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent 83b0996 commit 8dcec3c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

cmd/cue/cmd/testdata/script/def_openapi.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ cmp stdout expect-cue
1414
cue def -p foo openapi.json
1515
cmp stdout expect-cue
1616

17+
# cue to openapi
18+
cue def openapi+cue: expect-cue-out -o -
19+
cmp stdout expect-cue2
20+
1721
-- foo.cue --
1822
// Some clever title.
1923

@@ -181,3 +185,17 @@ Foo :: {
181185
b: >=0 & <10
182186
...
183187
}
188+
-- expect-cue2 --
189+
info: {
190+
title: "Some clever title."
191+
version: "v1"
192+
}
193+
Bar :: {
194+
foo: Foo
195+
...
196+
}
197+
Foo :: {
198+
a: int
199+
b: >=0 & <10
200+
...
201+
}

internal/encoding/encoding.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ func (i *Decoder) Next() {
7878
if i.err != nil {
7979
return
8080
}
81+
i.doInterpret()
82+
}
83+
84+
func (i *Decoder) doInterpret() {
8185
// Interpretations
8286
if i.interpret != nil {
8387
var r cue.Runtime
@@ -197,6 +201,9 @@ func NewDecoder(f *build.File, cfg *Config) *Decoder {
197201
i.file, i.err = cfg.ParseFile(path, r)
198202
}
199203
i.validate(i.file, f)
204+
if i.err == nil {
205+
i.doInterpret()
206+
}
200207
case build.JSON, build.JSONL:
201208
i.next = json.NewDecoder(nil, path, r).Extract
202209
i.Next()

0 commit comments

Comments
 (0)