Skip to content

Commit 90c9c95

Browse files
committed
encoding/openapi: remove most public API surfacing OrderedMap
OrderedMap has been deprecated since March 2020, and the presence of OrderedMap in the API is no longer useful and causes us to carry a significant amount of code forward. The legacy code around OrderedMap existed to help transition the Istio project more than four years ago; its use has long expired. Schemas, Pairs, and SetAll were not deprecated, but we did not use them and they either returned or took in deprecated OrderedMap values. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I9a631ba9734e384dafc655d3723746afd0a3a765 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201934 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent b24335b commit 90c9c95

File tree

2 files changed

+0
-87
lines changed

2 files changed

+0
-87
lines changed

encoding/openapi/openapi.go

-9
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,6 @@ func (c *Config) compose(inst cue.InstanceOrValue, schemas *ast.StructLit) (x *a
224224
), errs
225225
}
226226

227-
// Schemas extracts component/schemas from the CUE top-level types.
228-
func (g *Generator) Schemas(inst cue.InstanceOrValue) (*OrderedMap, error) {
229-
comps, err := schemas(g, inst)
230-
if err != nil {
231-
return nil, err
232-
}
233-
return (*OrderedMap)(comps), err
234-
}
235-
236227
var defaultConfig = &Config{}
237228

238229
// TODO

encoding/openapi/orderedmap.go

-78
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
package openapi
1616

1717
import (
18-
"fmt"
19-
2018
"cuelang.org/go/cue/ast"
21-
"cuelang.org/go/cue/literal"
22-
"cuelang.org/go/cue/token"
2319
internaljson "cuelang.org/go/internal/encoding/json"
2420
)
2521

@@ -31,74 +27,13 @@ import (
3127
// all the ast-related tooling.
3228
type OrderedMap ast.StructLit
3329

34-
// KeyValue associates a value with a key.
35-
type KeyValue struct {
36-
Key string
37-
Value interface{}
38-
}
39-
4030
// TODO: these functions are here to support backwards compatibility with Istio.
4131
// At some point, once this is removed from Istio, this can be removed.
4232

43-
func fromLegacy(x interface{}) ast.Expr {
44-
switch x := x.(type) {
45-
case *OrderedMap:
46-
return (*ast.StructLit)(x)
47-
case []*OrderedMap:
48-
a := make([]ast.Expr, len(x))
49-
for i, v := range x {
50-
a[i] = fromLegacy(v)
51-
}
52-
return ast.NewList(a...)
53-
case string:
54-
return ast.NewString(x)
55-
case ast.Expr:
56-
return x
57-
default:
58-
panic(fmt.Sprintf("unsupported type %T", x))
59-
}
60-
}
61-
62-
func toLegacy(x ast.Expr) interface{} {
63-
switch x := x.(type) {
64-
case *ast.StructLit:
65-
return (*OrderedMap)(x)
66-
case *ast.ListLit:
67-
a := make([]*OrderedMap, len(x.Elts))
68-
for i, v := range x.Elts {
69-
e, ok := v.(*ast.StructLit)
70-
if !ok {
71-
return x
72-
}
73-
a[i] = (*OrderedMap)(e)
74-
}
75-
return a
76-
case *ast.BasicLit:
77-
if x.Kind == token.STRING {
78-
str, err := literal.Unquote(x.Value)
79-
if err != nil {
80-
return x
81-
}
82-
return str
83-
}
84-
}
85-
return x
86-
}
87-
8833
func (m *OrderedMap) len() int {
8934
return len(m.Elts)
9035
}
9136

92-
// Pairs returns the KeyValue pairs associated with m.
93-
func (m *OrderedMap) Pairs() []KeyValue {
94-
kvs := make([]KeyValue, len(m.Elts))
95-
for i, e := range m.Elts {
96-
kvs[i].Key = label(e)
97-
kvs[i].Value = toLegacy(e.(*ast.Field).Value)
98-
}
99-
return kvs
100-
}
101-
10237
func (m *OrderedMap) find(key string) *ast.Field {
10338
for _, v := range m.Elts {
10439
f, ok := v.(*ast.Field)
@@ -146,19 +81,6 @@ func (m *OrderedMap) setExpr(key string, expr ast.Expr) {
14681
})
14782
}
14883

149-
// SetAll replaces existing key-value pairs with the given ones. The keys must
150-
// be unique.
151-
func (m *OrderedMap) SetAll(kvs []KeyValue) {
152-
var a []ast.Decl
153-
for _, kv := range kvs {
154-
a = append(a, &ast.Field{
155-
Label: ast.NewString(kv.Key),
156-
Value: fromLegacy(kv.Value),
157-
})
158-
}
159-
m.Elts = a
160-
}
161-
16284
// exists reports whether a key-value pair exists for the given key.
16385
func (m *OrderedMap) exists(key string) bool {
16486
return m.find(key) != nil

0 commit comments

Comments
 (0)