-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.go
More file actions
88 lines (76 loc) · 2.44 KB
/
header.go
File metadata and controls
88 lines (76 loc) · 2.44 KB
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
package openapi
// Header represents a header in OpenAPI
type Header struct {
Ref string `json:"$ref,omitempty"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
AllowEmptyValue bool `json:"allowEmptyValue,omitempty"`
Style string `json:"style,omitempty"`
Explode bool `json:"explode,omitempty"`
AllowReserved bool `json:"allowReserved,omitempty"`
Schema *Schema `json:"schema,omitempty"`
Example interface{} `json:"example,omitempty"`
Examples map[string]Example `json:"examples,omitempty"`
Content map[string]MediaType `json:"content,omitempty"`
}
// NewHeader creates a new header
func NewHeader() Header {
return Header{
Examples: make(map[string]Example),
Content: make(map[string]MediaType),
}
}
// WithDescription sets the description
func (h Header) WithDescription(description string) Header {
h.Description = description
return h
}
// WithRequired sets whether the header is required
func (h Header) WithRequired(required bool) Header {
h.Required = required
return h
}
// WithDeprecated marks the header as deprecated
func (h Header) WithDeprecated(deprecated bool) Header {
h.Deprecated = deprecated
return h
}
// WithAllowEmptyValue sets whether empty values are allowed
func (h Header) WithAllowEmptyValue(allow bool) Header {
h.AllowEmptyValue = allow
return h
}
// WithStyle sets the header style
func (h Header) WithStyle(style string) Header {
h.Style = style
return h
}
// WithExplode sets the explode option
func (h Header) WithExplode(explode bool) Header {
h.Explode = explode
return h
}
// WithAllowReserved sets whether reserved characters are allowed
func (h Header) WithAllowReserved(allow bool) Header {
h.AllowReserved = allow
return h
}
// WithSchema sets the schema for the header
func (h Header) WithSchema(schema *Schema) Header {
h.Schema = schema
return h
}
// WithExample sets an example for the header
func (h Header) WithExample(example interface{}) Header {
h.Example = example
return h
}
// WithExamples adds named examples
func (h Header) WithExamples(name string, example Example) Header {
if h.Examples == nil {
h.Examples = make(map[string]Example)
}
h.Examples[name] = example
return h
}