-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.go
74 lines (61 loc) · 1.63 KB
/
server.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
package oas
func NewServer(url string) *Server {
s := &Server{}
s.URL = url
return s
}
type WithServers struct {
Servers []*Server `json:"servers,omitempty"`
}
func (o *WithServers) AddServer(s *Server) {
if s == nil {
return
}
o.Servers = append(o.Servers, s)
}
type Server struct {
ServerObject
SpecExtensions
}
func (i Server) MarshalJSON() ([]byte, error) {
return flattenMarshalJSON(i.ServerObject, i.SpecExtensions)
}
func (i *Server) UnmarshalJSON(data []byte) error {
return flattenUnmarshalJSON(data, &i.ServerObject, &i.SpecExtensions)
}
type ServerObject struct {
URL string `json:"url"`
Description string `json:"description,omitempty"`
Variables map[string]*ServerVariable `json:"variables,omitempty"`
}
func (o *ServerObject) AddVariable(key string, v *ServerVariable) {
if v == nil {
return
}
if o.Variables == nil {
o.Variables = make(map[string]*ServerVariable)
}
o.Variables[key] = v
}
func NewServerVariable(defaultValue string) *ServerVariable {
return &ServerVariable{
ServerVariableObject: ServerVariableObject{
Default: defaultValue,
},
}
}
type ServerVariable struct {
ServerVariableObject
SpecExtensions
}
func (i ServerVariable) MarshalJSON() ([]byte, error) {
return flattenMarshalJSON(i.ServerVariableObject, i.SpecExtensions)
}
func (i *ServerVariable) UnmarshalJSON(data []byte) error {
return flattenUnmarshalJSON(data, &i.ServerVariableObject, &i.SpecExtensions)
}
type ServerVariableObject struct {
Default string `json:"default"`
Enum []string `json:"enum,omitempty"`
Description string `json:"description,omitempty"`
}