forked from davidebianchi/gswagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperation.go
48 lines (42 loc) · 1.33 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
package swagger
import (
"github.com/getkin/kin-openapi/openapi3"
)
// Operation type
type Operation struct {
*openapi3.Operation
}
// NewOperation returns an OpenApi operation.
func NewOperation() Operation {
return Operation{
openapi3.NewOperation(),
}
}
// AddRequestBody set request body into operation.
func (o *Operation) AddRequestBody(requestBody *openapi3.RequestBody) {
o.RequestBody = &openapi3.RequestBodyRef{
Value: requestBody,
}
}
// AddResponse add response to operation. It check if the description is present
// (otherwise default to empty string). This method does not add the default response,
// but it is always possible to add it manually.
func (o *Operation) AddResponse(status int, response *openapi3.Response) {
if o.Responses == nil {
o.Responses = &openapi3.Responses{}
}
if response.Description == nil {
// a description is required by kin openapi, so we set an empty description
// if it is not given.
response.WithDescription("")
}
o.Operation.AddResponse(status, response)
}
func (o *Operation) addSecurityRequirements(securityRequirements SecurityRequirements) {
if securityRequirements != nil && o.Security == nil {
o.Security = openapi3.NewSecurityRequirements()
}
for _, securityRequirement := range securityRequirements {
o.Security.With(openapi3.SecurityRequirement(securityRequirement))
}
}