-
Notifications
You must be signed in to change notification settings - Fork 2
/
oauth_flows_json_gen.go
147 lines (125 loc) · 3.6 KB
/
oauth_flows_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
136
137
138
139
140
141
142
143
144
145
146
147
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 oauthFlowsMarshalProxy struct {
Reference string `json:"$ref,omitempty"`
Implicit OAuthFlow `json:"implicit"`
Password OAuthFlow `json:"password"`
ClientCredentials OAuthFlow `json:"clientCredentials"`
AuthorizationCode OAuthFlow `json:"authorizationCode"`
}
type oauthFlowsUnmarshalProxy struct {
Reference string `json:"$ref,omitempty"`
Implicit json.RawMessage `json:"implicit"`
Password json.RawMessage `json:"password"`
ClientCredentials json.RawMessage `json:"clientCredentials"`
AuthorizationCode json.RawMessage `json:"authorizationCode"`
}
func (v *oauthFlows) MarshalJSON() ([]byte, error) {
var proxy oauthFlowsMarshalProxy
if len(v.reference) > 0 {
proxy.Reference = v.reference
return json.Marshal(proxy)
}
proxy.Implicit = v.implicit
proxy.Password = v.password
proxy.ClientCredentials = v.clientCredentials
proxy.AuthorizationCode = v.authorizationCode
return json.Marshal(proxy)
}
func (v *oauthFlows) UnmarshalJSON(data []byte) error {
var proxy oauthFlowsUnmarshalProxy
if err := json.Unmarshal(data, &proxy); err != nil {
return errors.Wrapf(err, `failed to unmarshal oauthFlows`)
}
if len(proxy.Reference) > 0 {
v.reference = proxy.Reference
return nil
}
if len(proxy.Implicit) > 0 {
var decoded oauthFlow
if err := json.Unmarshal(proxy.Implicit, &decoded); err != nil {
return errors.Wrap(err, `failed to unmarshal field Implicit`)
}
v.implicit = &decoded
}
if len(proxy.Password) > 0 {
var decoded oauthFlow
if err := json.Unmarshal(proxy.Password, &decoded); err != nil {
return errors.Wrap(err, `failed to unmarshal field Password`)
}
v.password = &decoded
}
if len(proxy.ClientCredentials) > 0 {
var decoded oauthFlow
if err := json.Unmarshal(proxy.ClientCredentials, &decoded); err != nil {
return errors.Wrap(err, `failed to unmarshal field ClientCredentials`)
}
v.clientCredentials = &decoded
}
if len(proxy.AuthorizationCode) > 0 {
var decoded oauthFlow
if err := json.Unmarshal(proxy.AuthorizationCode, &decoded); err != nil {
return errors.Wrap(err, `failed to unmarshal field AuthorizationCode`)
}
v.authorizationCode = &decoded
}
return nil
}
func (v *oauthFlows) 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 "implicit":
target = v.implicit
case "password":
target = v.password
case "clientCredentials":
target = v.clientCredentials
case "authorizationCode":
target = v.authorizationCode
default:
return nil, false
}
if qj, ok := target.(QueryJSONer); ok {
return qj.QueryJSON(path)
}
if path == "" {
return target, true
}
return nil, false
}
// OAuthFlowsFromJSON constructs a OAuthFlows from JSON buffer. `dst` must
// be a pointer to `OAuthFlows`
func OAuthFlowsFromJSON(buf []byte, dst interface{}) error {
v, ok := dst.(*OAuthFlows)
if !ok {
return errors.Errorf(`dst needs to be a pointer to OAuthFlows, but got %T`, dst)
}
var tmp oauthFlows
if err := json.Unmarshal(buf, &tmp); err != nil {
return errors.Wrap(err, `failed to unmarshal OAuthFlows`)
}
*v = &tmp
return nil
}