-
Notifications
You must be signed in to change notification settings - Fork 4
/
header.go
43 lines (35 loc) · 941 Bytes
/
header.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
package openapi
// codebeat:disable[TOO_MANY_IVARS]
// Header Object
type Header struct {
Description string
Required bool
Deprecated string
AllowEmptyValue bool `yaml:"allowEmptyValue"`
Style string
Explode bool
AllowReserved bool `yaml:"allowReserved"`
Schema *Schema
Example interface{}
Examples map[string]*Example
Content map[string]*MediaType
Ref string `yaml:"$ref"`
}
// Validate the values of Header object.
func (header Header) Validate() error {
validaters := []validater{}
if header.Schema != nil {
validaters = append(validaters, header.Schema)
}
if v, ok := header.Example.(validater); ok {
validaters = append(validaters, v)
}
// example has no validation
if len(header.Content) > 1 {
return ErrTooManyHeaderContent
}
for _, mediaType := range header.Content {
validaters = append(validaters, mediaType)
}
return validateAll(validaters)
}