Skip to content

Commit 3fb46c3

Browse files
committed
encoding/openapi: remove OrderedMap.Set
Both the receiver and method were deprecated for years, and its only internal use could be directly replaced by setExpr. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I15d0f66e35e91832065b54f7cda26954d94bea49 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201936 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent e7d9d47 commit 3fb46c3

File tree

4 files changed

+13
-35
lines changed

4 files changed

+13
-35
lines changed

encoding/openapi/build.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func schemas(g *Generator, inst cue.InstanceOrValue) (schemas *ast.StructLit, er
147147
if ref == "" {
148148
continue
149149
}
150-
c.schemas.Set(ref, c.build(sel, i.Value()))
150+
c.schemas.setExpr(ref, c.build(sel, i.Value()))
151151
}
152152

153153
// keep looping until a fixed point is reached.
@@ -168,7 +168,7 @@ func schemas(g *Generator, inst cue.InstanceOrValue) (schemas *ast.StructLit, er
168168
last := len(sels) - 1
169169
c.path = sels[:last]
170170
name := sels[last]
171-
c.schemas.Set(ext.ref, c.build(name, cue.Dereference(ext.value)))
171+
c.schemas.setExpr(ext.ref, c.build(name, cue.Dereference(ext.value)))
172172
}
173173
}
174174

@@ -752,9 +752,9 @@ func (b *builder) object(v cue.Value) {
752752
if ref == "" {
753753
continue
754754
}
755-
b.ctx.schemas.Set(ref, schema)
755+
b.ctx.schemas.setExpr(ref, schema)
756756
case !b.isNonCore() || len(schema.Elts) > 0:
757-
properties.Set(label, schema)
757+
properties.setExpr(label, schema)
758758
}
759759
}
760760

@@ -1127,13 +1127,13 @@ func setType(t *oaSchema, b *builder) {
11271127
if b.typ != "" {
11281128
if b.core == nil || (b.core.typ != b.typ && !b.ctx.structural) {
11291129
if !t.exists("type") {
1130-
t.Set("type", ast.NewString(b.typ))
1130+
t.setExpr("type", ast.NewString(b.typ))
11311131
}
11321132
}
11331133
}
11341134
if b.format != "" {
11351135
if b.core == nil || b.core.format != b.format {
1136-
t.Set("format", ast.NewString(b.format))
1136+
t.setExpr("format", ast.NewString(b.format))
11371137
}
11381138
}
11391139
}
@@ -1156,7 +1156,7 @@ func (b *builder) setSingle(key string, v ast.Expr, drop bool) {
11561156
b.failf(cue.Value{}, "more than one value added for key %q", key)
11571157
}
11581158
}
1159-
b.singleFields.Set(key, v)
1159+
b.singleFields.setExpr(key, v)
11601160
}
11611161

11621162
func (b *builder) set(key string, v ast.Expr) {
@@ -1167,7 +1167,7 @@ func (b *builder) set(key string, v ast.Expr) {
11671167
b.current = &OrderedMap{}
11681168
b.allOf = append(b.allOf, (*ast.StructLit)(b.current))
11691169
}
1170-
b.current.Set(key, v)
1170+
b.current.setExpr(key, v)
11711171
}
11721172

11731173
func (b *builder) kv(key string, value ast.Expr) *ast.StructLit {
@@ -1208,14 +1208,14 @@ func (b *builder) finish() *ast.StructLit {
12081208
exprs = append(exprs, s)
12091209
}
12101210
t = &OrderedMap{}
1211-
t.Set("allOf", ast.NewList(exprs...))
1211+
t.setExpr("allOf", ast.NewList(exprs...))
12121212
}
12131213
if b.singleFields != nil {
12141214
b.singleFields.Elts = append(b.singleFields.Elts, t.Elts...)
12151215
t = b.singleFields
12161216
}
12171217
if b.deprecated {
1218-
t.Set("deprecated", ast.NewBool(true))
1218+
t.setExpr("deprecated", ast.NewBool(true))
12191219
}
12201220
setType(t, b)
12211221
sortSchema((*ast.StructLit)(t))

encoding/openapi/crd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (b *builder) coreSchema() *ast.StructLit {
7777
p := &OrderedMap{}
7878
for _, k := range b.keys {
7979
sub := b.properties[k]
80-
p.Set(k, sub.coreSchemaWithName(cue.Str(k)))
80+
p.setExpr(k, sub.coreSchemaWithName(cue.Str(k)))
8181
}
8282
if p.len() > 0 || b.items != nil {
8383
b.setType("object", "")

encoding/openapi/openapi.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ func (c *Config) compose(inst cue.InstanceOrValue, schemas *ast.StructLit) (x *a
197197
)
198198
} else {
199199
m := (*OrderedMap)(info)
200-
m.Set("title", ast.NewString(title))
201-
m.Set("version", ast.NewString(version))
200+
m.setExpr("title", ast.NewString(title))
201+
m.setExpr("version", ast.NewString(version))
202202
}
203203

204204
case *ast.StructLit:

encoding/openapi/orderedmap.go

-22
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,6 @@ func (m *OrderedMap) find(key string) *ast.Field {
4747
return nil
4848
}
4949

50-
// Set sets a key value pair. If a pair with the same key already existed, it
51-
// will be replaced with the new value. Otherwise, the new value is added to
52-
// the end. The value must be of type string, [ast.Expr], or [*OrderedMap].
53-
//
54-
// Deprecated: use cuelang.org/go/cue/ast to manipulate ASTs.
55-
func (m *OrderedMap) Set(key string, x interface{}) {
56-
switch x := x.(type) {
57-
case *OrderedMap:
58-
m.setExpr(key, (*ast.StructLit)(x))
59-
case string:
60-
m.setExpr(key, ast.NewString(x))
61-
case ast.Expr:
62-
m.setExpr(key, x)
63-
default:
64-
v, err := toCUE("Set", x)
65-
if err != nil {
66-
panic(err)
67-
}
68-
m.setExpr(key, v)
69-
}
70-
}
71-
7250
func (m *OrderedMap) setExpr(key string, expr ast.Expr) {
7351
if f := m.find(key); f != nil {
7452
f.Value = expr

0 commit comments

Comments
 (0)