Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d657071

Browse files
committedMar 6, 2025·
encoding/openapi: add support for openapi extension attributes in builder
1 parent 5d2da07 commit d657071

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎encoding/openapi/build.go

+21
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"cuelang.org/go/cue/ast"
2929
"cuelang.org/go/cue/errors"
3030
"cuelang.org/go/cue/token"
31+
cuejson "cuelang.org/go/encoding/json"
3132
"cuelang.org/go/internal"
3233
"cuelang.org/go/internal/core/adt"
3334
)
@@ -740,6 +741,26 @@ func (b *builder) object(v cue.Value) {
740741
b.setSingle("properties", (*ast.StructLit)(properties), false)
741742
}
742743

744+
attr := v.Attribute("openapi")
745+
for i := 0; i < attr.NumArgs(); i++ {
746+
key, value := attr.Arg(i)
747+
if key != "extension" {
748+
continue
749+
}
750+
751+
parts := strings.SplitN(value, ":", 2)
752+
if len(parts) != 2 {
753+
b.failf(v, "invalid openapi extension attribute %q: %v must be in the format key:value", key, value)
754+
} else {
755+
extension, err := cuejson.Extract(key, []byte(parts[1]))
756+
if err != nil {
757+
b.failf(v, "invalid openapi extension attribute %q: %v", key, err)
758+
}
759+
760+
b.setSingle(parts[0], extension, true)
761+
}
762+
}
763+
743764
if t := v.LookupPath(cue.MakePath(cue.AnyString)); t.Exists() &&
744765
(b.core == nil || b.core.items == nil) && b.checkCycle(t) {
745766
schema := b.schema(nil, cue.AnyString, t)

0 commit comments

Comments
 (0)
Please sign in to comment.