Skip to content

Commit 9f2c2fe

Browse files
committed
encoding/openapi: unexport OrderedMap
Now that no other exported APIs directly reference OrderedMap, and OrderedMap itself does not export any methods either, start unexporting it after being deprecated for over four years. We remove support from Config.Info, as end users can no longer reference the OrderedMap type for use in that API. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I81be113edfe1a058e43c9f4f028d6891cec1044d Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201937 Reviewed-by: Roger Peppe <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 3fb46c3 commit 9f2c2fe

File tree

4 files changed

+24
-34
lines changed

4 files changed

+24
-34
lines changed

encoding/openapi/build.go

+14-16
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type buildContext struct {
4444
descFunc func(v cue.Value) string
4545
fieldFilter *regexp.Regexp
4646

47-
schemas *OrderedMap
47+
schemas *orderedMap
4848

4949
// Track external schemas.
5050
externalRefs map[string]*externalType
@@ -70,8 +70,6 @@ type externalType struct {
7070
value cue.Value
7171
}
7272

73-
type oaSchema = OrderedMap
74-
7573
type typeFunc func(b *builder, a cue.Value)
7674

7775
func schemas(g *Generator, inst cue.InstanceOrValue) (schemas *ast.StructLit, err error) {
@@ -105,7 +103,7 @@ func schemas(g *Generator, inst cue.InstanceOrValue) (schemas *ast.StructLit, er
105103
structural: g.ExpandReferences,
106104
nameFunc: g.NameFunc,
107105
descFunc: g.DescriptionFunc,
108-
schemas: &OrderedMap{},
106+
schemas: &orderedMap{},
109107
externalRefs: map[string]*externalType{},
110108
fieldFilter: fieldFilter,
111109
}
@@ -726,13 +724,13 @@ func (b *builder) object(v cue.Value) {
726724
b.setFilter("Schema", "required", ast.NewList(required...))
727725
}
728726

729-
var properties *OrderedMap
727+
var properties *orderedMap
730728
if b.singleFields != nil {
731729
properties = b.singleFields.getMap("properties")
732730
}
733731
hasProps := properties != nil
734732
if !hasProps {
735-
properties = &OrderedMap{}
733+
properties = &orderedMap{}
736734
}
737735

738736
for i, _ := v.Fields(cue.Optional(true), cue.Definitions(true)); i.Next(); {
@@ -1077,8 +1075,8 @@ type builder struct {
10771075
ctx *buildContext
10781076
typ string
10791077
format string
1080-
singleFields *oaSchema
1081-
current *oaSchema
1078+
singleFields *orderedMap
1079+
current *orderedMap
10821080
allOf []*ast.StructLit
10831081
deprecated bool
10841082

@@ -1123,7 +1121,7 @@ func (b *builder) setType(t, format string) {
11231121
}
11241122
}
11251123

1126-
func setType(t *oaSchema, b *builder) {
1124+
func setType(t *orderedMap, b *builder) {
11271125
if b.typ != "" {
11281126
if b.core == nil || (b.core.typ != b.typ && !b.ctx.structural) {
11291127
if !t.exists("type") {
@@ -1149,7 +1147,7 @@ func (b *builder) setFilter(schema, key string, v ast.Expr) {
11491147
// setSingle sets a value of which there should only be one.
11501148
func (b *builder) setSingle(key string, v ast.Expr, drop bool) {
11511149
if b.singleFields == nil {
1152-
b.singleFields = &OrderedMap{}
1150+
b.singleFields = &orderedMap{}
11531151
}
11541152
if b.singleFields.exists(key) {
11551153
if !drop {
@@ -1161,10 +1159,10 @@ func (b *builder) setSingle(key string, v ast.Expr, drop bool) {
11611159

11621160
func (b *builder) set(key string, v ast.Expr) {
11631161
if b.current == nil {
1164-
b.current = &OrderedMap{}
1162+
b.current = &orderedMap{}
11651163
b.allOf = append(b.allOf, (*ast.StructLit)(b.current))
11661164
} else if b.current.exists(key) {
1167-
b.current = &OrderedMap{}
1165+
b.current = &orderedMap{}
11681166
b.allOf = append(b.allOf, (*ast.StructLit)(b.current))
11691167
}
11701168
b.current.setExpr(key, v)
@@ -1179,14 +1177,14 @@ func (b *builder) setNot(key string, value ast.Expr) {
11791177
}
11801178

11811179
func (b *builder) finish() *ast.StructLit {
1182-
var t *OrderedMap
1180+
var t *orderedMap
11831181

11841182
if b.filled != nil {
11851183
return b.filled
11861184
}
11871185
switch len(b.allOf) {
11881186
case 0:
1189-
t = &OrderedMap{}
1187+
t = &orderedMap{}
11901188

11911189
case 1:
11921190
hasRef := false
@@ -1197,7 +1195,7 @@ func (b *builder) finish() *ast.StructLit {
11971195
}
11981196
}
11991197
if !hasRef || b.singleFields == nil {
1200-
t = (*OrderedMap)(b.allOf[0])
1198+
t = (*orderedMap)(b.allOf[0])
12011199
break
12021200
}
12031201
fallthrough
@@ -1207,7 +1205,7 @@ func (b *builder) finish() *ast.StructLit {
12071205
for _, s := range b.allOf {
12081206
exprs = append(exprs, s)
12091207
}
1210-
t = &OrderedMap{}
1208+
t = &orderedMap{}
12111209
t.setExpr("allOf", ast.NewList(exprs...))
12121210
}
12131211
if b.singleFields != nil {

encoding/openapi/crd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (b *builder) coreSchema() *ast.StructLit {
7474
}
7575

7676
case cue.StructKind:
77-
p := &OrderedMap{}
77+
p := &orderedMap{}
7878
for _, k := range b.keys {
7979
sub := b.properties[k]
8080
p.setExpr(k, sub.coreSchemaWithName(cue.Str(k)))

encoding/openapi/openapi.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ func (c *Config) compose(inst cue.InstanceOrValue, schemas *ast.StructLit) (x *a
172172
}
173173
}
174174

175-
// Support of OrderedMap is mostly for backwards compatibility.
176175
switch x := c.Info.(type) {
177176
case nil:
178177
if title == "" {
@@ -196,17 +195,13 @@ func (c *Config) compose(inst cue.InstanceOrValue, schemas *ast.StructLit) (x *a
196195
"version", ast.NewString(version),
197196
)
198197
} else {
199-
m := (*OrderedMap)(info)
198+
m := (*orderedMap)(info)
200199
m.setExpr("title", ast.NewString(title))
201200
m.setExpr("version", ast.NewString(version))
202201
}
203202

204203
case *ast.StructLit:
205204
info = x
206-
case *OrderedMap:
207-
info = (*ast.StructLit)(x)
208-
case OrderedMap:
209-
info = (*ast.StructLit)(&x)
210205
default:
211206
x, err := toCUE("info section", x)
212207
if err != nil {

encoding/openapi/orderedmap.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,19 @@ import (
1818
"cuelang.org/go/cue/ast"
1919
)
2020

21-
// An OrderedMap is a set of key-value pairs that preserves the order in which
21+
// An orderedMap is a set of key-value pairs that preserves the order in which
2222
// items were added.
2323
//
2424
// Deprecated: the API now returns an ast.File. This allows OpenAPI to be
2525
// represented as JSON, YAML, or CUE data, in addition to being able to use
2626
// all the ast-related tooling.
27-
type OrderedMap ast.StructLit
27+
type orderedMap ast.StructLit
2828

29-
// TODO: these functions are here to support backwards compatibility with Istio.
30-
// At some point, once this is removed from Istio, this can be removed.
31-
32-
func (m *OrderedMap) len() int {
29+
func (m *orderedMap) len() int {
3330
return len(m.Elts)
3431
}
3532

36-
func (m *OrderedMap) find(key string) *ast.Field {
33+
func (m *orderedMap) find(key string) *ast.Field {
3734
for _, v := range m.Elts {
3835
f, ok := v.(*ast.Field)
3936
if !ok {
@@ -47,7 +44,7 @@ func (m *OrderedMap) find(key string) *ast.Field {
4744
return nil
4845
}
4946

50-
func (m *OrderedMap) setExpr(key string, expr ast.Expr) {
47+
func (m *orderedMap) setExpr(key string, expr ast.Expr) {
5148
if f := m.find(key); f != nil {
5249
f.Value = expr
5350
return
@@ -59,15 +56,15 @@ func (m *OrderedMap) setExpr(key string, expr ast.Expr) {
5956
}
6057

6158
// exists reports whether a key-value pair exists for the given key.
62-
func (m *OrderedMap) exists(key string) bool {
59+
func (m *orderedMap) exists(key string) bool {
6360
return m.find(key) != nil
6461
}
6562

6663
// exists reports whether a key-value pair exists for the given key.
67-
func (m *OrderedMap) getMap(key string) *OrderedMap {
64+
func (m *orderedMap) getMap(key string) *orderedMap {
6865
f := m.find(key)
6966
if f == nil {
7067
return nil
7168
}
72-
return (*OrderedMap)(f.Value.(*ast.StructLit))
69+
return (*orderedMap)(f.Value.(*ast.StructLit))
7370
}

0 commit comments

Comments
 (0)