-
Notifications
You must be signed in to change notification settings - Fork 19
/
parameter.go
78 lines (67 loc) · 2.09 KB
/
parameter.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
package spec3
// Parameter describes a single operation parameter.
// A unique parameter is defined by a combination of a name and location.
type Parameter struct {
VendorExtensible
Reference
Name string `json:"name"`
In string `json:"in"`
Description string `json:"description"`
Required bool `json:"required"`
Deprecated bool `json:"deprecated"`
AllowEmptyValue bool `json:"allowEmptyValue"`
Style string `json:"style"`
Explode bool `json:"explode"`
AllowReserved bool `json:"allowReserved"`
Schema Schema `json:"schema"`
Example interface{} `json:"example"`
Examples OrderedExamples `json:"examples"`
Contents OrderedMediaTypes `json:"contents"`
}
type OrderedParameters struct {
data OrderedMap
}
func NewOrderedParameters() OrderedParameters {
return OrderedParameters{
data: OrderedMap{
filter: MatchNonEmptyKeys,
},
}
}
// Get gets the security requirement by key
func (s *OrderedParameters) Get(key string) *Parameter {
v := s.data.Get(key)
if v == nil {
return nil
}
return v.(*Parameter)
}
// GetOK checks if the key exists in the security requirement
func (s *OrderedParameters) GetOK(key string) (*Parameter, bool) {
v, ok := s.data.GetOK(key)
if !ok {
return nil, ok
}
sr, ok := v.(*Parameter)
return sr, ok
}
// Set sets the value to the security requirement
func (s *OrderedParameters) Set(key string, val *Parameter) bool {
return s.data.Set(key, val)
}
// ForEach executes the function for each security requirement
func (s *OrderedParameters) ForEach(fn func(string, *Parameter) error) error {
s.data.ForEach(func(key string, val interface{}) error {
response, _ := val.(*Parameter)
if err := fn(key, response); err != nil {
return err
}
return nil
})
return nil
}
// Keys gets the list of keys
func (s *OrderedParameters) Keys() []string {
return s.data.Keys()
}
// TODO: (s *OrderedParameters) Implement Marshal & Unmarshal -> JSON, YAML