Skip to content

Commit

Permalink
encoding/openapi: rewrite uses of deprecated cue.Value methods
Browse files Browse the repository at this point in the history
cue.Value.Reference can be rewritten with cue.Value.ReferencePath,
and cue.Value.Elem can be rewritten with cue.Value.LookupPath
with either cue.AnyString or cue.AnyIndex, depending on whether
the value is a struct or a list.

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: I092707aafe89feb4dbf3e7fd9980f0deb73940a4
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1206354
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Paul Jolly <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mvdan committed Jan 3, 2025
1 parent e44b17d commit 7373f67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions encoding/openapi/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (b *builder) value(v cue.Value, f typeFunc) (isRef bool) {
default:
a := appendSplit(nil, cue.OrOp, v)
for i, v := range a {
if _, r := v.Reference(); len(r) == 0 {
if _, r := v.ReferencePath(); len(r.Selectors()) == 0 {
a[i] = v.Eval()
}
}
Expand Down Expand Up @@ -750,7 +750,7 @@ func (b *builder) object(v cue.Value) {
b.setSingle("properties", (*ast.StructLit)(properties), false)
}

if t, ok := v.Elem(); ok &&
if t := v.LookupPath(cue.MakePath(cue.AnyString)); t.Exists() &&
(b.core == nil || b.core.items == nil) && b.checkCycle(t) {
schema := b.schema(nil, cue.AnyString, t)
if len(schema.Elts) > 0 {
Expand Down Expand Up @@ -852,7 +852,7 @@ func (b *builder) array(v cue.Value) {
}

if !hasMax || int64(len(items)) < maxLength {
if typ, ok := v.Elem(); ok && b.checkCycle(typ) {
if typ := v.LookupPath(cue.MakePath(cue.AnyIndex)); typ.Exists() && b.checkCycle(typ) {
var core *builder
if b.core != nil {
core = b.core.items
Expand Down
8 changes: 4 additions & 4 deletions encoding/openapi/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func (b *builder) buildCore(v cue.Value) {
defer b.popNode()

if !b.ctx.expandRefs {
_, r := v.Reference()
if len(r) > 0 {
_, r := v.ReferencePath()
if len(r.Selectors()) > 0 {
return
}
}
Expand All @@ -128,7 +128,7 @@ func (b *builder) buildCore(v cue.Value) {

switch b.kind {
case cue.StructKind:
if typ, ok := v.Elem(); ok {
if typ := v.LookupPath(cue.MakePath(cue.AnyString)); typ.Exists() {
if !b.checkCycle(typ) {
return
}
Expand All @@ -140,7 +140,7 @@ func (b *builder) buildCore(v cue.Value) {
b.buildCoreStruct(v)

case cue.ListKind:
if typ, ok := v.Elem(); ok {
if typ := v.LookupPath(cue.MakePath(cue.AnyIndex)); typ.Exists() {
if !b.checkCycle(typ) {
return
}
Expand Down

0 comments on commit 7373f67

Please sign in to comment.