-
Notifications
You must be signed in to change notification settings - Fork 19
/
callback.go
119 lines (101 loc) · 3.14 KB
/
callback.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
package spec3
// Callback A map of possible out-of band callbacks related to the parent operation.
// Each value in the map is a Path Item Object that describes a set of requests that may be initiated by the API provider and the expected responses.
// The key value used to identify the callback object is an expression, evaluated at runtime, that identifies a URL to use for the callback operation.
type Callback struct {
data OrderedMap
}
// NewCallback creates a new instance of Callback with correct filter
func NewCallback() Callback {
return Callback{
data: OrderedMap{
filter: MatchNonEmptyKeys, // TODO: check if keys are some regex or just any non empty string
},
}
}
// Get gets the security requirement by key
func (s *Callback) Get(key string) *PathItem {
v := s.data.Get(key)
if v == nil {
return nil
}
return v.(*PathItem)
}
// GetOK checks if the key exists in the security requirement
func (s *Callback) GetOK(key string) (*PathItem, bool) {
v, ok := s.data.GetOK(key)
if !ok {
return nil, ok
}
sr, ok := v.(*PathItem)
return sr, ok
}
// Set sets the value to the security requirement
func (s *Callback) Set(key string, val *PathItem) bool {
return s.data.Set(key, val)
}
// ForEach executes the function for each security requirement
func (s *Callback) ForEach(fn func(string, *PathItem) error) error {
s.data.ForEach(func(key string, val interface{}) error {
response, _ := val.(*PathItem)
if err := fn(key, response); err != nil {
return err
}
return nil
})
return nil
}
// Keys gets the list of keys
func (s *Callback) Keys() []string {
return s.data.Keys()
}
// TODO: (s *Callback) Implement Marshal & Unmarshal -> JSON, YAML
// OrderedCallbacks is a map between a variable name and its value. The value is used for substitution in the server's URL template.
type OrderedCallbacks struct {
data OrderedMap
}
// NewOrderedCallbacks creates a new instance of OrderedCallbacks with correct filter
func NewOrderedCallbacks() OrderedCallbacks {
return OrderedCallbacks{
data: OrderedMap{
filter: MatchNonEmptyKeys, // TODO: check if keys are some regex or just any non empty string
},
}
}
// Get gets the security requirement by key
func (s *OrderedCallbacks) Get(key string) *Callback {
v := s.data.Get(key)
if v == nil {
return nil
}
return v.(*Callback)
}
// GetOK checks if the key exists in the security requirement
func (s *OrderedCallbacks) GetOK(key string) (*Callback, bool) {
v, ok := s.data.GetOK(key)
if !ok {
return nil, ok
}
sr, ok := v.(*Callback)
return sr, ok
}
// Set sets the value to the security requirement
func (s *OrderedCallbacks) Set(key string, val *Callback) bool {
return s.data.Set(key, val)
}
// ForEach executes the function for each security requirement
func (s *OrderedCallbacks) ForEach(fn func(string, *Callback) error) error {
s.data.ForEach(func(key string, val interface{}) error {
response, _ := val.(*Callback)
if err := fn(key, response); err != nil {
return err
}
return nil
})
return nil
}
// Keys gets the list of keys
func (s *OrderedCallbacks) Keys() []string {
return s.data.Keys()
}
// TODO: (s *OrderedCallbacks) Implement Marshal & Unmarshal -> JSON, YAML