-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtag_slice.go
132 lines (112 loc) · 2.64 KB
/
tag_slice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package openapi
import (
"encoding/json"
"github.com/chanced/transcode"
"gopkg.in/yaml.v3"
)
type TagSlice struct {
Location `json:"-"`
Items []*Tag
}
func (tl *TagSlice) Nodes() []Node {
if tl == nil {
return nil
}
return downcastNodes(tl.nodes())
}
func (tl *TagSlice) nodes() []node {
edges := make([]node, len(tl.Items))
for i, item := range tl.Items {
edges[i] = item
}
return edges
}
func (*TagSlice) Kind() Kind { return KindTagSlice }
func (ts *TagSlice) Refs() []Ref {
if ts == nil {
return nil
}
var refs []Ref
for _, item := range ts.Items {
refs = append(refs, item.Refs()...)
}
return refs
}
// func (ts TagSlice) ResolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if err := ptr.Validate(); err != nil {
// return nil, err
// }
// return ts.resolveNodeByPointer(ptr)
// }
// func (ts *TagSlice) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if ptr.IsRoot() {
// return ts, nil
// }
// nxt, tok, _ := ptr.Next()
// idx, err := tok.Int()
// if err != nil {
// return nil, newErrNotResolvable(ts.Location.AbsoluteLocation(), tok)
// }
// if idx < 0 {
// return nil, newErrNotResolvable(ts.Location.AbsoluteLocation(), tok)
// }
// if idx >= len(ts.Items) {
// return nil, newErrNotFound(ts.Location.AbsoluteLocation(), tok)
// }
// return ts.Items[idx].resolveNodeByPointer(nxt)
// }
func (ts *TagSlice) MarshalJSON() ([]byte, error) {
return json.Marshal(ts.Items)
}
func (ts *TagSlice) UnmarshalJSON(data []byte) error {
var items []*Tag
if err := json.Unmarshal(data, &items); err != nil {
return err
}
*ts = TagSlice{
Items: items,
}
return nil
}
// UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface
func (t TagSlice) MarshalYAML() (interface{}, error) {
j, err := t.MarshalJSON()
if err != nil {
return nil, err
}
var v interface{}
err = json.Unmarshal(j, &v)
if err != nil {
return nil, err
}
return v, nil
}
// UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface
func (t *TagSlice) UnmarshalYAML(value *yaml.Node) error {
v, err := yaml.Marshal(value)
if err != nil {
return err
}
j, err := transcode.JSONFromYAML(v)
if err != nil {
return err
}
return json.Unmarshal(j, t)
}
func (ts *TagSlice) isNil() bool {
return ts == nil
}
func (ts TagSlice) location() Location {
return ts.Location
}
func (*TagSlice) mapKind() Kind { return KindUndefined }
func (*TagSlice) sliceKind() Kind { return KindUndefined }
func (ts *TagSlice) setLocation(loc Location) error {
if ts == nil {
return nil
}
ts.Location = loc
return nil
}
func (*TagSlice) Anchors() (*Anchors, error) { return nil, nil }
var _ node = (*TagSlice)(nil)