-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpaths.go
85 lines (69 loc) · 1.85 KB
/
paths.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
package oas
import (
"encoding/json"
)
type Paths struct {
Paths map[string]*PathItem
SpecExtensions
}
func (p *Paths) AddOperation(method HttpMethod, path string, op *Operation) {
if p.Paths == nil {
p.Paths = make(map[string]*PathItem)
}
if p.Paths[path] == nil {
p.Paths[path] = &PathItem{}
}
p.Paths[path].AddOperation(method, op)
}
func (p Paths) MarshalJSON() ([]byte, error) {
return flattenMarshalJSON(p.Paths, p.SpecExtensions)
}
func (p *Paths) UnmarshalJSON(data []byte) error {
return flattenUnmarshalJSON(data, &p.Paths, &p.SpecExtensions)
}
type PathItem struct {
Operations
PathItemObject
SpecExtensions
}
func (i PathItem) MarshalJSON() ([]byte, error) {
return flattenMarshalJSON(i.Operations, i.PathItemObject, i.SpecExtensions)
}
func (i *PathItem) UnmarshalJSON(data []byte) error {
return flattenUnmarshalJSON(data, &i.Operations, &i.PathItemObject, &i.SpecExtensions)
}
type HttpMethod string
const (
GET HttpMethod = "get"
PUT HttpMethod = "put"
POST HttpMethod = "post"
DELETE HttpMethod = "delete"
OPTIONS HttpMethod = "options"
HEAD HttpMethod = "head"
PATCH HttpMethod = "patch"
TRACE HttpMethod = "trace"
)
type Operations struct {
Operations map[HttpMethod]*Operation
}
func (v *Operations) AddOperation(method HttpMethod, op *Operation) {
if v == nil {
return
}
if v.Operations == nil {
v.Operations = make(map[HttpMethod]*Operation)
}
v.Operations[method] = op
}
func (v Operations) MarshalJSON() ([]byte, error) {
return json.Marshal(v.Operations)
}
func (v *Operations) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &v.Operations)
}
type PathItemObject struct {
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Servers []*Server `json:"servers,omitempty"`
Parameters []*Parameter `json:"parameters,omitempty"`
}