cue: encoding/openapi: exporter does not work with self-contained option when one type extends another
What version of CUE are you using (cue version)?
Note: using cue as a library and not the executable. Compiling with v0.12.0
$ cue version v0.12.0
go version go1.23.1
-buildmode exe
-compiler gc
DefaultGODEBUG asynctimerchan=1,gotypesalias=0,httpservecontentkeepheaders=1,tls3des=1,tlskyber=0,x509keypairleaf=0,x509negativeserial=1
CGO_ENABLED 1
GOARCH arm64
GOOS darwin
GOARM64 v8.0
cue.lang.version v0.12.0
Does this issue reproduce with the latest stable release?
Yes.
Context
I have a program that uses cue as a library to export an openapi schema from a set of cue types. The custom program is needed to enable the SelfContained and ExpandReferences options for the openapi exporter (which don’t seem to be available on the command line).
I need self-contained schemas because this is a schema that is given to Kubernetes for a custom resource definition.
What did you do?
# -- evalv3 --
env CUE_EXPERIMENT=evalv3=1
exec go mod tidy
exec go run main.go
# -- evalv2 --
env CUE_EXPERIMENT=evalv3=0
exec go mod tidy
exec go run main.go
-- go.mod --
module mod.example
-- deps.go --
package deps
import _ "cuelang.org/go/cmd/cue"
-- go.mod --
module example.com/cue-openapi-bug
go 1.21.3
require cuelang.org/go v0.12.0
-- main.go --
package main
import (
"bytes"
"fmt"
"log"
"encoding/json"
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/encoding/openapi"
)
func run() error {
cueSource := `
#Identified: {
id: string
}
#Named: {
#Identified
name: string
}
#Entity: {
thing: #Named
}
`
runtime := cuecontext.New()
val := runtime.CompileString(cueSource)
if val.Err() != nil {
return val.Err()
}
b, err := openapi.Gen(val, &openapi.Config{
Info: map[string]any{
"title": "XRD schemas",
"description": "general",
"version": "0.1.0",
},
SelfContained: true,
ExpandReferences: true,
})
if err != nil {
return err
}
var res bytes.Buffer
err = json.Indent(&res, b, "", " ")
if err != nil {
return err
}
fmt.Println(res.String())
return nil
}
func main() {
if err := run(); err != nil {
log.Fatalln(err)
}
}
What did you expect to see?
A passing test.
What did you see instead?
Error message that says (note the use of testscript -continue):
$ ts -continue repro.txtar
# -- evalv3 -- (0.398s)
> env CUE_EXPERIMENT=evalv3=1
> exec go mod tidy
> exec go run main.go
[stderr]
unsupported op . for object type ({
id: string
})
exit status 1
[exit status 1]
FAIL: /tmp/testscript3601686356/repro.txtar/script.txtar:7: unexpected command failure
# -- evalv2 -- (0.315s)
> env CUE_EXPERIMENT=evalv3=0
> exec go mod tidy
> exec go run main.go
[stderr]
unsupported op . for object type ({
id: string
})
exit status 1
[exit status 1]
FAIL: /tmp/testscript3601686356/repro.txtar/script.txtar:12: unexpected command failure
error running repro.txtar in /tmp/testscript3601686356/repro.txtar
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 15 (6 by maintainers)
@gotwarlost thanks for the updates. I’d suggest jumping on a quick call to chat this through. I’ll email you offline