-
Notifications
You must be signed in to change notification settings - Fork 2
/
server_variable.go
115 lines (99 loc) · 3.05 KB
/
server_variable.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
package openapi
import (
"encoding/json"
"github.com/chanced/transcode"
"gopkg.in/yaml.v3"
)
// ServerVariable for server URL template substitution.
type ServerVariable struct {
// An enumeration of string values to be used if the substitution options
// are from a limited set. The array MUST NOT be empty.
Enum Texts `json:"enum"`
// The default value to use for substitution, which SHALL be sent if an
// alternate value is not supplied. Note this behavior is different than the
// Schema Object's treatment of default values, because in those cases
// parameter values are optional. If the enum is defined, the value MUST
// exist in the enum's values.
//
// *required*
Default Text `json:"default"`
// An optional description for the server variable. CommonMark syntax MAY be
// used for rich text representation.
Description Text `json:"description,omitempty"`
Location `json:"-"`
Extensions `json:"-"`
}
func (sv *ServerVariable) Nodes() []Node {
if sv == nil {
return nil
}
return downcastNodes(sv.nodes())
}
func (sv *ServerVariable) nodes() []node { return nil }
func (*ServerVariable) Refs() []Ref { return nil }
// func (sv *ServerVariable) ResolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if err := ptr.Validate(); err != nil {
// return nil, err
// }
// return sv.resolveNodeByPointer(ptr)
// }
// func (sv *ServerVariable) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if ptr.IsRoot() {
// return sv, nil
// }
// tok, _ := ptr.NextToken()
// return nil, newErrNotResolvable(sv.Location.AbsoluteLocation(), tok)
// }
func (*ServerVariable) Kind() Kind { return KindServerVariable }
func (*ServerVariable) mapKind() Kind { return KindServerVariableMap }
func (*ServerVariable) sliceKind() Kind { return KindUndefined }
func (sv *ServerVariable) setLocation(loc Location) error {
if sv == nil {
return nil
}
sv.Location = loc
return nil
}
// MarshalJSON marshals JSON
func (sv ServerVariable) MarshalJSON() ([]byte, error) {
type servervariable ServerVariable
return marshalExtendedJSON(servervariable(sv))
}
// UnmarshalJSON unmarshals JSON
func (sv *ServerVariable) UnmarshalJSON(data []byte) error {
type servervariable ServerVariable
var v servervariable
err := unmarshalExtendedJSON(data, &v)
*sv = ServerVariable(v)
return err
}
// UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface
func (sv ServerVariable) MarshalYAML() (interface{}, error) {
j, err := sv.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 (sv *ServerVariable) 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, sv)
}
func (sv *ServerVariable) Anchors() (*Anchors, error) {
return nil, nil
}
func (sv *ServerVariable) isNil() bool { return sv == nil }
var _ node = (*ServerVariable)(nil)