forked from go-openapi/spec3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink.go
73 lines (62 loc) · 2.12 KB
/
link.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
package spec3
// Link represents a possible design-time link for a response.
// The presence of a link does not guarantee the caller's ability to successfully invoke it, rather it provides a known relationship and traversal mechanism between responses and other operations.
type Link struct {
VendorExtensible
Reference
OperationRef string `json:"operationRef,omitempty"`
OperationID string `json:"operationId,omitempty"`
Parameters map[string]interface{} `json:"parameters,omitempty"`
RequestBody interface{} `json:"requestBody,omitempty"`
Description string `json:"description,omitempty"`
Server Server `json:"server,omitempty"`
}
// OrderedLinks is a map between a variable name and its value. The value is used for substitution in the server's URL template.
type OrderedLinks struct {
data OrderedMap
}
// NewOrderedLinks creates a new instance of OrderedLinks with correct filter
func NewOrderedLinks() OrderedLinks {
return OrderedLinks{
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 *OrderedLinks) Get(key string) *Link {
v := s.data.Get(key)
if v == nil {
return nil
}
return v.(*Link)
}
// GetOK checks if the key exists in the security requirement
func (s *OrderedLinks) GetOK(key string) (*Link, bool) {
v, ok := s.data.GetOK(key)
if !ok {
return nil, ok
}
sr, ok := v.(*Link)
return sr, ok
}
// Set sets the value to the security requirement
func (s *OrderedLinks) Set(key string, val *Link) bool {
return s.data.Set(key, val)
}
// ForEach executes the function for each security requirement
func (s *OrderedLinks) ForEach(fn func(string, *Link) error) error {
s.data.ForEach(func(key string, val interface{}) error {
response, _ := val.(*Link)
if err := fn(key, response); err != nil {
return err
}
return nil
})
return nil
}
// Keys gets the list of keys
func (s *OrderedLinks) Keys() []string {
return s.data.Keys()
}
// TODO: (s *OrderedLinks) Implement Marshal & Unmarshal -> JSON, YAML