From 7373f67fbe99ef600b3d47430b57b6caae6bec6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 26 Dec 2024 18:11:55 +0000 Subject: [PATCH] encoding/openapi: rewrite uses of deprecated cue.Value methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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í Change-Id: I092707aafe89feb4dbf3e7fd9980f0deb73940a4 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1206354 Unity-Result: CUE porcuepine Reviewed-by: Paul Jolly TryBot-Result: CUEcueckoo --- encoding/openapi/build.go | 6 +++--- encoding/openapi/crd.go | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/encoding/openapi/build.go b/encoding/openapi/build.go index 252dfc736..c35846282 100644 --- a/encoding/openapi/build.go +++ b/encoding/openapi/build.go @@ -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() } } @@ -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 { @@ -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 diff --git a/encoding/openapi/crd.go b/encoding/openapi/crd.go index 79826d177..9c9e2634f 100644 --- a/encoding/openapi/crd.go +++ b/encoding/openapi/crd.go @@ -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 } } @@ -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 } @@ -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 } -- 2.51.2