-
Notifications
You must be signed in to change notification settings - Fork 2
/
link_json_gen.go
135 lines (119 loc) · 3.2 KB
/
link_json_gen.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package openapi
// This file was automatically generated.
// DO NOT EDIT MANUALLY. All changes will be lost
import (
"encoding/json"
"log"
"strings"
"github.com/pkg/errors"
)
var _ = log.Printf
var _ = json.Unmarshal
var _ = errors.Cause
type linkMarshalProxy struct {
Reference string `json:"$ref,omitempty"`
OperationRef string `json:"operationRef"`
OperationID string `json:"operationId"`
Parameters InterfaceMap `json:"parameters"`
RequestBody interface{} `json:"requestBody"`
Description string `json:"description"`
Server Server `json:"server"`
}
type linkUnmarshalProxy struct {
Reference string `json:"$ref,omitempty"`
OperationRef string `json:"operationRef"`
OperationID string `json:"operationId"`
Parameters InterfaceMap `json:"parameters"`
RequestBody interface{} `json:"requestBody"`
Description string `json:"description"`
Server json.RawMessage `json:"server"`
}
func (v *link) MarshalJSON() ([]byte, error) {
var proxy linkMarshalProxy
if len(v.reference) > 0 {
proxy.Reference = v.reference
return json.Marshal(proxy)
}
proxy.OperationRef = v.operationRef
proxy.OperationID = v.operationID
proxy.Parameters = v.parameters
proxy.RequestBody = v.requestBody
proxy.Description = v.description
proxy.Server = v.server
return json.Marshal(proxy)
}
func (v *link) UnmarshalJSON(data []byte) error {
var proxy linkUnmarshalProxy
if err := json.Unmarshal(data, &proxy); err != nil {
return errors.Wrapf(err, `failed to unmarshal link`)
}
if len(proxy.Reference) > 0 {
v.reference = proxy.Reference
return nil
}
v.operationRef = proxy.OperationRef
v.operationID = proxy.OperationID
v.parameters = proxy.Parameters
v.requestBody = proxy.RequestBody
v.description = proxy.Description
if len(proxy.Server) > 0 {
var decoded server
if err := json.Unmarshal(proxy.Server, &decoded); err != nil {
return errors.Wrap(err, `failed to unmarshal field Server`)
}
v.server = &decoded
}
return nil
}
func (v *link) QueryJSON(path string) (ret interface{}, ok bool) {
path = strings.TrimLeftFunc(path, func(r rune) bool { return r == '#' || r == '/' })
if path == "" {
return v, true
}
var frag string
if i := strings.Index(path, "/"); i > -1 {
frag = path[:i]
path = path[i+1:]
} else {
frag = path
path = ""
}
var target interface{}
switch frag {
case "operationRef":
target = v.operationRef
case "operationId":
target = v.operationID
case "parameters":
target = v.parameters
case "requestBody":
target = v.requestBody
case "description":
target = v.description
case "server":
target = v.server
default:
return nil, false
}
if qj, ok := target.(QueryJSONer); ok {
return qj.QueryJSON(path)
}
if path == "" {
return target, true
}
return nil, false
}
// LinkFromJSON constructs a Link from JSON buffer. `dst` must
// be a pointer to `Link`
func LinkFromJSON(buf []byte, dst interface{}) error {
v, ok := dst.(*Link)
if !ok {
return errors.Errorf(`dst needs to be a pointer to Link, but got %T`, dst)
}
var tmp link
if err := json.Unmarshal(buf, &tmp); err != nil {
return errors.Wrap(err, `failed to unmarshal Link`)
}
*v = &tmp
return nil
}