-
Notifications
You must be signed in to change notification settings - Fork 2
/
request_body.go
142 lines (121 loc) · 3.45 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package openapi
import (
"encoding/json"
"github.com/chanced/transcode"
"gopkg.in/yaml.v3"
)
// RequestBodyMap is a map of RequestBody
type RequestBodyMap = ComponentMap[*RequestBody]
// RequestBody describes a single request body.
type RequestBody struct {
Location `json:"-"`
Extensions `json:"-"`
// A brief description of the request body. This could contain examples of
// use. CommonMark syntax MAY be used for rich text representation.
Description Text `json:"description,omitempty"`
// The content of the request body. The key is a media type or media type range and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text
//
// *required*
Content *ContentMap `json:"content,omitempty"`
// Determines if the request body is required in the request. Defaults to false.
Required bool `json:"required,omitempty"`
}
func (rb *RequestBody) Nodes() []Node {
if rb == nil {
return nil
}
return downcastNodes(rb.nodes())
}
func (rb *RequestBody) nodes() []node {
if rb == nil {
return nil
}
return appendEdges(nil, rb.Content)
}
func (rb *RequestBody) Refs() []Ref {
if rb == nil {
return nil
}
return rb.Content.Refs()
}
func (rb *RequestBody) isNil() bool { return rb == nil }
func (rb *RequestBody) Anchors() (*Anchors, error) {
if rb == nil {
return nil, nil
}
return rb.Content.Anchors()
}
// func (rb *RequestBody) ResolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if err := ptr.Validate(); err != nil {
// return nil, err
// }
// return rb.resolveNodeByPointer(ptr)
// }
// func (rb *RequestBody) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if ptr.IsRoot() {
// return rb, nil
// }
// nxt, tok, _ := ptr.Next()
// switch tok {
// case "content":
// if rb.Content == nil {
// return nil, newErrNotFound(rb.AbsoluteLocation(), tok)
// }
// return rb.Content.resolveNodeByPointer(nxt)
// default:
// return nil, newErrNotResolvable(rb.Location.AbsoluteLocation(), tok)
// }
// }
func (*RequestBody) Kind() Kind { return KindRequestBody }
func (*RequestBody) mapKind() Kind { return KindRequestBodyMap }
func (*RequestBody) sliceKind() Kind { return KindUndefined }
// MarshalJSON marshals h into JSON
func (rb RequestBody) MarshalJSON() ([]byte, error) {
type requestbody RequestBody
return marshalExtendedJSON(requestbody(rb))
}
// UnmarshalJSON unmarshals json into rb
func (rb *RequestBody) UnmarshalJSON(data []byte) error {
type requestbody RequestBody
var v requestbody
err := unmarshalExtendedJSON(data, &v)
*rb = RequestBody(v)
return err
}
// UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface
func (rb RequestBody) MarshalYAML() (interface{}, error) {
j, err := rb.MarshalJSON()
if err != nil {
return nil, err
}
var v interface{}
err = json.Unmarshal(j, &v)
if err != nil {
return nil, err
}
return v, nil
}
// UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface
func (rb *RequestBody) UnmarshalYAML(value *yaml.Node) error {
v, err := yaml.Marshal(value)
if err != nil {
return err
}
j, err := transcode.JSONFromYAML(v)
if err != nil {
return err
}
return json.Unmarshal(j, rb)
}
func (rb *RequestBody) setLocation(loc Location) error {
if rb == nil {
return nil
}
rb.Location = loc
if err := rb.Content.setLocation(loc.AppendLocation("content")); err != nil {
return err
}
return nil
}
func (*RequestBody) refable() {}
var _ node = (*RequestBody)(nil)