-
Notifications
You must be signed in to change notification settings - Fork 3
/
operation.go
107 lines (88 loc) · 2.43 KB
/
operation.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
package oas
func NewOperation(operationId string) *Operation {
op := &Operation{}
op.OperationId = operationId
return op
}
type Operation struct {
OperationObject
SpecExtensions
}
func (op Operation) WithTags(tags ...string) *Operation {
op.Tags = append(op.Tags, tags...)
return &op
}
func (op Operation) WithSummary(summary string) *Operation {
op.Summary = summary
return &op
}
func (op Operation) WithDesc(desc string) *Operation {
op.Description = desc
return &op
}
func (op Operation) MarshalJSON() ([]byte, error) {
return flattenMarshalJSON(op.OperationObject, op.SpecExtensions)
}
func (op *Operation) UnmarshalJSON(data []byte) error {
return flattenUnmarshalJSON(data, &op.OperationObject, &op.SpecExtensions)
}
type OperationObject struct {
Tags []string `json:"tags,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"`
OperationId string `json:"operationId"`
WithParameters
RequestBody *RequestBody `json:"requestBody,omitempty"`
Responses Responses `json:"responses"`
WithCallbacks
WithSecurityRequirement
Deprecated bool `json:"deprecated,omitempty"`
WithServers
}
func (o *OperationObject) SetRequestBody(rb *RequestBody) {
o.RequestBody = rb
}
func (o *OperationObject) AddResponse(statusCode int, r *Response) {
o.Responses.AddResponse(statusCode, r)
}
func (o *OperationObject) SetDefaultResponse(r *Response) {
o.Responses.SetDefaultResponse(r)
}
type WithCallbacks struct {
Callbacks map[string]*Callback `json:"callbacks,omitempty"`
}
func (o *WithCallbacks) AddCallback(name string, c *Callback) {
if c == nil {
return
}
if o.Callbacks == nil {
o.Callbacks = make(map[string]*Callback)
}
o.Callbacks[name] = c
}
func NewCallback(method HttpMethod, rule RuntimeExpression, op *Operation) *Callback {
return &Callback{
CallbackObject: CallbackObject{
rule: &PathItem{
Operations: Operations{
Operations: map[HttpMethod]*Operation{
method: op,
},
},
},
},
}
}
type Callback struct {
Reference
CallbackObject
SpecExtensions
}
func (i Callback) MarshalJSON() ([]byte, error) {
return i.MarshalJSONRefFirst(i.CallbackObject, i.SpecExtensions)
}
func (i *Callback) UnmarshalJSON(data []byte) error {
return i.UnmarshalJSONRefFirst(data, &i.CallbackObject, &i.SpecExtensions)
}
type CallbackObject map[RuntimeExpression]*PathItem