-
Notifications
You must be signed in to change notification settings - Fork 3
/
media_type.go
95 lines (78 loc) · 2.04 KB
/
media_type.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
package oas
type WithContentOrSchema struct {
Schema *Schema `json:"schema,omitempty"`
WithContent
}
func (o *WithContentOrSchema) SetSchema(s *Schema) {
o.Content = nil
o.Schema = s
}
func (o *WithContentOrSchema) AddContent(contentType string, mt *MediaType) {
o.Schema = nil
o.WithContent.AddContent(contentType, mt)
}
type WithContent struct {
Content map[string]*MediaType `json:"content,omitempty"`
}
func (o *WithContent) AddContent(contentType string, mt *MediaType) {
if mt == nil {
return
}
if o.Content == nil {
o.Content = make(map[string]*MediaType)
}
o.Content[contentType] = mt
}
func NewMediaTypeWithSchema(s *Schema) *MediaType {
mt := &MediaType{}
mt.Schema = s
return mt
}
type MediaType struct {
MediaTypeObject
SpecExtensions
}
func (i MediaType) MarshalJSON() ([]byte, error) {
return flattenMarshalJSON(i.MediaTypeObject, i.SpecExtensions)
}
func (i *MediaType) UnmarshalJSON(data []byte) error {
return flattenUnmarshalJSON(data, &i.MediaTypeObject, &i.SpecExtensions)
}
type MediaTypeObject struct {
Schema *Schema `json:"schema,omitempty"`
Example interface{} `json:"example,omitempty"`
WithExamples
WithEncoding
}
type WithEncoding struct {
Encoding map[string]*Encoding `json:"encoding,omitempty"`
}
func (o *WithEncoding) AddEncoding(name string, e *Encoding) {
if e == nil {
return
}
if o.Encoding == nil {
o.Encoding = make(map[string]*Encoding)
}
o.Encoding[name] = e
}
func NewEncoding() *Encoding {
return &Encoding{}
}
type Encoding struct {
EncodingObject
SpecExtensions
}
func (i Encoding) MarshalJSON() ([]byte, error) {
return flattenMarshalJSON(i.EncodingObject, i.SpecExtensions)
}
func (i *Encoding) UnmarshalJSON(data []byte) error {
return flattenUnmarshalJSON(data, &i.EncodingObject, &i.SpecExtensions)
}
type EncodingObject struct {
ContentType string `json:"contentType,omitempty"`
WithHeaders
Style ParameterStyle `json:"style,omitempty"`
Explode bool `json:"explode,omitempty"`
AllowReserved bool `json:"allowReserved,omitempty"`
}