-
Notifications
You must be signed in to change notification settings - Fork 2
/
security_scheme.go
190 lines (163 loc) · 4.82 KB
/
security_scheme.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package openapi
import (
"encoding/json"
"github.com/chanced/transcode"
"gopkg.in/yaml.v3"
)
const (
// SecuritySchemeTypeAPIKey = "apiKey"
SecuritySchemeTypeAPIKey Text = "apiKey"
// SecuritySchemeTypeHTTP = "http"
SecuritySchemeTypeHTTP Text = "http"
// SecuritySchemeTypeMutualTLS = mutualTLS
SecuritySchemeTypeMutualTLS Text = "mutualTLS"
// SecuritySchemeTypeOAuth2 = oauth2
SecuritySchemeTypeOAuth2 Text = "oauth2"
// SecuritySchemeTypeOpenIDConnect = "openIdConnect"
SecuritySchemeTypeOpenIDConnect Text = "openIdConnect"
)
// SecuritySchemeMap is a map of SecurityScheme
type SecuritySchemeMap = ComponentMap[*SecurityScheme]
// SecurityScheme defines a security scheme that can be used by the operations.
type SecurityScheme struct {
Extensions `json:"-"`
Location `json:"-"`
// The type of the security scheme.
//
// *required
Type Text `json:"type,omitempty"`
// Any description for security scheme. CommonMark syntax MAY be used for
// rich text representation.
Description Text `json:"description,omitempty"`
// The name of the header, query or cookie parameter to be used.
//
// Applies to: API Key
//
// *required*
Name Text `json:"name,omitempty"`
// The location of the API key. Valid values are "query", "header" or "cookie".
//
// Applies to: APIKey
//
// *required*
In In `json:"in,omitempty"`
// The name of the HTTP Authorization scheme to be used in the Authorization
// header as defined in RFC7235. The values used SHOULD be registered in the
// IANA Authentication Scheme registry.
//
// *required*
Scheme Text `json:"scheme,omitempty"`
// http ("bearer") A hint to the client to identify how the bearer token is
// formatted. Bearer tokens are usually generated by an authorization
// server, so this information is primarily for documentation purposes.
BearerFormat Text `json:"bearerFormat,omitempty"`
// An object containing configuration information for the flow types supported.
//
// *required*
Flows *OAuthFlows `json:"flows,omitempty"`
// OpenId Connect URL to discover OAuth2 configuration values. This MUST be
// in the form of a URL. The OpenID Connect standard requires the use of
// TLS.
//
// *required*
OpenIDConnectURL Text `json:"openIdConnect,omitempty"`
}
func (ss *SecurityScheme) Nodes() []Node {
if ss == nil {
return nil
}
return downcastNodes(ss.nodes())
}
func (ss *SecurityScheme) nodes() []node {
if ss == nil {
return nil
}
return appendEdges(nil, ss.Flows)
}
func (ss *SecurityScheme) Refs() []Ref {
if ss == nil {
return nil
}
return ss.Flows.Refs()
}
func (ss *SecurityScheme) isNil() bool { return ss == nil }
func (ss *SecurityScheme) Anchors() (*Anchors, error) {
if ss == nil {
return nil, nil
}
return ss.Flows.Anchors()
}
func (s *SecurityScheme) setLocation(loc Location) error {
if s == nil {
return nil
}
s.Location = loc
return s.Flows.setLocation(loc.AppendLocation("flows"))
}
// UnmarshalJSON unmarshals JSON
func (ss *SecurityScheme) UnmarshalJSON(data []byte) error {
type securityscheme SecurityScheme
var v securityscheme
err := unmarshalExtendedJSON(data, &v)
*ss = SecurityScheme(v)
return err
}
// MarshalJSON marshals JSON
func (ss SecurityScheme) MarshalJSON() ([]byte, error) {
type securityscheme SecurityScheme
return marshalExtendedJSON(securityscheme(ss))
}
// UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface
func (ss SecurityScheme) MarshalYAML() (interface{}, error) {
j, err := ss.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 (ss *SecurityScheme) 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, ss)
}
func (*SecurityScheme) Kind() Kind { return KindSecurityScheme }
func (*SecurityScheme) mapKind() Kind { return KindSecuritySchemeMap }
func (*SecurityScheme) sliceKind() Kind { return KindUndefined }
func (*SecurityScheme) refable() {}
var _ node = (*SecurityScheme)(nil)
// func (ss *SecurityScheme) ResolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if err := ptr.Validate(); err != nil {
// return nil, err
// }
// return ss.resolveNodeByPointer(ptr)
// }
// func (ss *SecurityScheme) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if ptr.IsRoot() {
// return ss, nil
// }
// nxt, tok, _ := ptr.Next()
// switch nxt {
// case "flows":
// if nxt.IsRoot() {
// return ss.Flows, nil
// }
// if ss.Flows == nil {
// return nil, newErrNotFound(ss.AbsoluteLocation(), tok)
// }
// return ss.Flows.resolveNodeByPointer(nxt)
// default:
// return nil, newErrNotResolvable(ss.AbsoluteLocation(), tok)
// }
// }