forked from getkin/kin-openapi
/
request_body.go
69 lines (56 loc) · 1.66 KB
/
request_body.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
package openapi3
import (
"context"
"github.com/getkin/kin-openapi/jsoninfo"
)
// RequestBody is specified by OpenAPI/Swagger 3.0 standard.
type RequestBody struct {
ExtensionProps
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Content Content `json:"content,omitempty"`
}
func NewRequestBody() *RequestBody {
return &RequestBody{}
}
func (requestBody *RequestBody) WithDescription(value string) *RequestBody {
requestBody.Description = value
return requestBody
}
func (requestBody *RequestBody) WithRequired(value bool) *RequestBody {
requestBody.Required = value
return requestBody
}
func (requestBody *RequestBody) WithContent(content Content) *RequestBody {
requestBody.Content = content
return requestBody
}
func (requestBody *RequestBody) WithJSONSchemaRef(value *SchemaRef) *RequestBody {
requestBody.Content = NewContentWithJSONSchemaRef(value)
return requestBody
}
func (requestBody *RequestBody) WithJSONSchema(value *Schema) *RequestBody {
requestBody.Content = NewContentWithJSONSchema(value)
return requestBody
}
func (requestBody *RequestBody) GetMediaType(mediaType string) *MediaType {
m := requestBody.Content
if m == nil {
return nil
}
return m[mediaType]
}
func (requestBody *RequestBody) MarshalJSON() ([]byte, error) {
return jsoninfo.MarshalStrictStruct(requestBody)
}
func (requestBody *RequestBody) UnmarshalJSON(data []byte) error {
return jsoninfo.UnmarshalStrictStruct(data, requestBody)
}
func (requestBody *RequestBody) Validate(c context.Context) error {
if v := requestBody.Content; v != nil {
if err := v.Validate(c); err != nil {
return err
}
}
return nil
}