-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlink.go
37 lines (32 loc) · 898 Bytes
/
link.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
package openapi
import "errors"
// codebeat:disable[TOO_MANY_IVARS]
// Link Object
type Link struct {
OperationRef string `yaml:"operationRef"`
OperationID string `yaml:"operationId"`
Parameters map[string]interface{}
RequestBody interface{} `yaml:"requestBody"`
Description string
Server *Server
Ref string `yaml:"$ref"`
}
// Validate the values of Link object.
func (link Link) Validate() error {
if link.OperationRef != "" && link.OperationID != "" {
return errors.New("operationRef and operationId are mutually exclusive")
}
validaters := []validater{}
for _, i := range link.Parameters {
if v, ok := i.(validater); ok {
validaters = append(validaters, v)
}
}
if v, ok := link.RequestBody.(validater); ok {
validaters = append(validaters, v)
}
if link.Server != nil {
validaters = append(validaters, link.Server)
}
return validateAll(validaters)
}