-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpath_item.go
392 lines (352 loc) · 10.3 KB
/
path_item.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
package openapi
import (
"encoding/json"
"github.com/chanced/transcode"
"gopkg.in/yaml.v3"
)
// PathItem describes the operations available on a single path. A PathItem Item MAY
// be empty, due to ACL constraints. The path itself is still exposed to the
// documentation viewer but they will not know which operations and parameters
// are available.
type PathItem struct {
Location `json:"-"`
Extensions `json:"-"`
// An optional, string summary, intended to apply to all operations in this path.
Summary Text `json:"summary,omitempty"`
// An optional, string description, intended to apply to all operations in
// this path. CommonMark syntax MAY be used for rich text representation.
Description Text `json:"description,omitempty"`
// A list of parameters that are applicable for all the operations described
// under this path. These parameters can be overridden at the operation
// level, but cannot be removed there. The list MUST NOT include duplicated
// parameters. A unique parameter is defined by a combination of a name and
// location. The list can use the Reference Object to link to parameters
// that are defined at the OpenAPI Object's components/parameters.
Parameters *ParameterSlice `json:"parameters,omitempty"`
// A definition of a GET operation on this path.
Get *Operation `json:"get,omitempty"`
// A definition of a PUT operation on this path.
Put *Operation `json:"put,omitempty"`
// A definition of a POST operation on this path.
Post *Operation `json:"post,omitempty"`
// A definition of a DELETE operation on this path.
Delete *Operation `json:"delete,omitempty"`
// A definition of a OPTIONS operation on this path.
Options *Operation `json:"options,omitempty"`
// A definition of a HEAD operation on this path.
Head *Operation `json:"head,omitempty"`
// A definition of a PATCH operation on this path.
Patch *Operation `json:"patch,omitempty"`
// A definition of a TRACE operation on this path.
Trace *Operation `json:"trace,omitempty"`
// An alternative server array to service all operations in this path.
Servers *ServerSlice `json:"servers,omitempty"`
}
func (pi *PathItem) Nodes() []Node {
if pi == nil {
return nil
}
return downcastNodes(pi.nodes())
}
func (pi *PathItem) nodes() []node {
if pi == nil {
return nil
}
var edges []node
edges = appendEdges(edges, pi.Servers)
edges = appendEdges(edges, pi.Parameters)
edges = appendEdges(edges, pi.Get)
edges = appendEdges(edges, pi.Put)
edges = appendEdges(edges, pi.Post)
edges = appendEdges(edges, pi.Delete)
edges = appendEdges(edges, pi.Options)
edges = appendEdges(edges, pi.Head)
edges = appendEdges(edges, pi.Patch)
edges = appendEdges(edges, pi.Trace)
return edges
}
func (pi *PathItem) ref() Ref { return nil }
func (pi *PathItem) Refs() []Ref {
if pi == nil {
return nil
}
var refs []Ref
refs = append(refs, pi.Servers.Refs()...)
refs = append(refs, pi.Parameters.Refs()...)
refs = append(refs, pi.Get.Refs()...)
refs = append(refs, pi.Put.Refs()...)
refs = append(refs, pi.Post.Refs()...)
refs = append(refs, pi.Delete.Refs()...)
refs = append(refs, pi.Options.Refs()...)
refs = append(refs, pi.Head.Refs()...)
refs = append(refs, pi.Patch.Refs()...)
refs = append(refs, pi.Trace.Refs()...)
return refs
}
func (pi *PathItem) Anchors() (*Anchors, error) {
if pi == nil {
return nil, nil
}
var anchors *Anchors
var err error
if anchors, err = anchors.merge(pi.Get.Anchors()); err != nil {
return nil, err
}
if anchors, err = anchors.merge(pi.Put.Anchors()); err != nil {
return nil, err
}
if anchors, err = anchors.merge(pi.Post.Anchors()); err != nil {
return nil, err
}
if anchors, err = anchors.merge(pi.Delete.Anchors()); err != nil {
return nil, err
}
if anchors, err = anchors.merge(pi.Options.Anchors()); err != nil {
return nil, err
}
if anchors, err = anchors.merge(pi.Head.Anchors()); err != nil {
return nil, err
}
if anchors, err = anchors.merge(pi.Patch.Anchors()); err != nil {
return nil, err
}
if anchors, err = anchors.merge(pi.Trace.Anchors()); err != nil {
return nil, err
}
if anchors, err = anchors.merge(pi.Servers.Anchors()); err != nil {
return nil, err
}
if anchors, err = anchors.merge(pi.Parameters.Anchors()); err != nil {
return nil, err
}
return anchors, err
}
func (*PathItem) mapKind() Kind { return KindPathItemMap }
func (*PathItem) sliceKind() Kind { return KindUndefined }
func (p *PathItem) setLocation(loc Location) error {
if p == nil {
return nil
}
p.Location = loc
var err error
if err = p.Delete.setLocation(loc.AppendLocation("delete")); err != nil {
return err
}
if err = p.Get.setLocation(loc.AppendLocation("get")); err != nil {
return err
}
if err = p.Head.setLocation(loc.AppendLocation("head")); err != nil {
return err
}
if err = p.Options.setLocation(loc.AppendLocation("options")); err != nil {
return err
}
if err = p.Patch.setLocation(loc.AppendLocation("patch")); err != nil {
return err
}
if err = p.Post.setLocation(loc.AppendLocation("post")); err != nil {
return err
}
if err = p.Put.setLocation(loc.AppendLocation("put")); err != nil {
return err
}
if err = p.Trace.setLocation(loc.AppendLocation("trace")); err != nil {
return err
}
if err = p.Parameters.setLocation(loc.AppendLocation("parameters")); err != nil {
return err
}
if err = p.Servers.setLocation(loc.AppendLocation("servers")); err != nil {
return err
}
return nil
}
// MarshalJSON marshals p into JSON
func (p PathItem) MarshalJSON() ([]byte, error) {
type path PathItem
return marshalExtendedJSON(path(p))
}
// UnmarshalJSON unmarshals json into p
func (p *PathItem) UnmarshalJSON(data []byte) error {
type path PathItem
var v path
if err := unmarshalExtendedJSON(data, &v); err != nil {
return err
}
*p = PathItem(v)
return nil
}
// UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface
func (p PathItem) MarshalYAML() (interface{}, error) {
j, err := p.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 (p *PathItem) 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, p)
}
func (*PathItem) Kind() Kind { return KindPathItem }
func (pi *PathItem) isNil() bool { return pi == nil }
func (*PathItem) refable() {}
var _ node = (*PathItem)(nil)
// func (pi *PathItem) ResolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if err := ptr.Validate(); err != nil {
// return nil, err
// }
// return pi.resolveNodeByPointer(ptr)
// }
// func (pi *PathItem) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if ptr.IsRoot() {
// return pi, nil
// }
// nxt, tok, _ := ptr.Next()
// switch tok {
// case "get":
// if pi.Get == nil {
// return nil, newErrNotFound(pi.Location.AbsoluteLocation(), tok)
// }
// return pi.resolveNodeByPointer(nxt)
// case "put":
// if pi.Put == nil {
// return nil, newErrNotFound(pi.Location.AbsoluteLocation(), tok)
// }
// return pi.Put.resolveNodeByPointer(nxt)
// case "post":
// if pi.Post == nil {
// return nil, newErrNotFound(pi.Location.AbsoluteLocation(), tok)
// }
// return pi.Post.resolveNodeByPointer(nxt)
// case "delete":
// if pi.Delete == nil {
// return nil, newErrNotFound(pi.AbsoluteLocation(), tok)
// }
// return pi.Delete.resolveNodeByPointer(nxt)
// case "options":
// if pi.Options == nil {
// return nil, newErrNotFound(pi.AbsoluteLocation(), tok)
// }
// return pi.Options.resolveNodeByPointer(nxt)
// case "head":
// if pi.Head == nil {
// return nil, newErrNotFound(pi.AbsoluteLocation(), tok)
// }
// return pi.Head.resolveNodeByPointer(nxt)
// case "patch":
// if pi.Patch == nil {
// return nil, newErrNotFound(pi.AbsoluteLocation(), tok)
// }
// return pi.Patch.resolveNodeByPointer(nxt)
// case "trace":
// if pi.Trace == nil {
// return nil, newErrNotFound(pi.AbsoluteLocation(), tok)
// }
// return pi.Trace.resolveNodeByPointer(nxt)
// case "servers":
// if pi.Servers == nil {
// return nil, newErrNotFound(pi.AbsoluteLocation(), tok)
// }
// return pi.Servers.resolveNodeByPointer(nxt)
// case "parameters":
// if pi.Parameters == nil {
// return nil, newErrNotFound(pi.AbsoluteLocation(), tok)
// }
// return pi.Parameters.resolveNodeByPointer(nxt)
// default:
// return nil, newErrNotResolvable(pi.Location.AbsoluteLocation(), tok)
// }
// }
// func (pi *PathItem) Walk(v Visitor) error {
// if v == nil {
// return nil
// }
// var err error
// v, err = v.Visit(pi)
// if err != nil {
// return err
// }
// if v == nil {
// return nil
// }
// v, err = v.VisitPathItem(pi)
// if err != nil {
// return err
// }
// if v == nil {
// return nil
// }
// if pi.Parameters != nil {
// if err = pi.Parameters.Walk(v); err != nil {
// return err
// }
// }
// if pi.Servers != nil {
// if err = pi.Servers.Walk(v); err != nil {
// return err
// }
// }
// var op OperationItem
// if pi.Get != nil {
// op = OperationItem{Operation: pi.Get, Method: MethodGet}
// if err = op.Walk(v); err != nil {
// return err
// }
// }
// if pi.Put != nil {
// op = OperationItem{Operation: pi.Put, Method: MethodPut}
// if err = op.Walk(v); err != nil {
// return err
// }
// }
// if pi.Post != nil {
// op = OperationItem{Operation: pi.Post, Method: MethodPost}
// if err = op.Walk(v); err != nil {
// return err
// }
// }
// if pi.Delete != nil {
// op = OperationItem{Operation: pi.Delete, Method: MethodDelete}
// if err = op.Walk(v); err != nil {
// return err
// }
// }
// if pi.Options != nil {
// op = OperationItem{Operation: pi.Options, Method: MethodOptions}
// if err = op.Walk(v); err != nil {
// return err
// }
// }
// if pi.Head != nil {
// op = OperationItem{Operation: pi.Head, Method: MethodHead}
// if err = op.Walk(v); err != nil {
// return err
// }
// }
// if pi.Patch != nil {
// op = OperationItem{Operation: pi.Patch, Method: MethodPatch}
// if err = op.Walk(v); err != nil {
// return err
// }
// }
// if pi.Trace != nil {
// if err = pi.Trace.Walk(v); err != nil {
// return err
// }
// }
// return nil
// }