-
Notifications
You must be signed in to change notification settings - Fork 2
/
components_json_gen.go
145 lines (131 loc) · 3.97 KB
/
components_json_gen.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
143
144
145
package openapi
// This file was automatically generated.
// DO NOT EDIT MANUALLY. All changes will be lost
import (
"encoding/json"
"log"
"strings"
"github.com/pkg/errors"
)
var _ = log.Printf
var _ = json.Unmarshal
var _ = errors.Cause
type componentsMarshalProxy struct {
Reference string `json:"$ref,omitempty"`
Schemas SchemaMap `json:"schemas,omitempty"`
Responses ResponseMap `json:"responses,omitempty"`
Parameters ParameterMap `json:"parameters,omitempty"`
Examples ExampleMap `json:"examples,omitempty"`
RequestBodies RequestBodyMap `json:"requestBodies,omitempty"`
Headers HeaderMap `json:"headers,omitempty"`
SecuritySchemes SecuritySchemeMap `json:"securitySchemes,omitempty"`
Links LinkMap `json:"links,omitempty"`
Callbacks CallbackMap `json:"callbacks,omitempty"`
}
type componentsUnmarshalProxy struct {
Reference string `json:"$ref,omitempty"`
Schemas SchemaMap `json:"schemas,omitempty"`
Responses ResponseMap `json:"responses,omitempty"`
Parameters ParameterMap `json:"parameters,omitempty"`
Examples ExampleMap `json:"examples,omitempty"`
RequestBodies RequestBodyMap `json:"requestBodies,omitempty"`
Headers HeaderMap `json:"headers,omitempty"`
SecuritySchemes SecuritySchemeMap `json:"securitySchemes,omitempty"`
Links LinkMap `json:"links,omitempty"`
Callbacks CallbackMap `json:"callbacks,omitempty"`
}
func (v *components) MarshalJSON() ([]byte, error) {
var proxy componentsMarshalProxy
if len(v.reference) > 0 {
proxy.Reference = v.reference
return json.Marshal(proxy)
}
proxy.Schemas = v.schemas
proxy.Responses = v.responses
proxy.Parameters = v.parameters
proxy.Examples = v.examples
proxy.RequestBodies = v.requestBodies
proxy.Headers = v.headers
proxy.SecuritySchemes = v.securitySchemes
proxy.Links = v.links
proxy.Callbacks = v.callbacks
return json.Marshal(proxy)
}
func (v *components) UnmarshalJSON(data []byte) error {
var proxy componentsUnmarshalProxy
if err := json.Unmarshal(data, &proxy); err != nil {
return errors.Wrapf(err, `failed to unmarshal components`)
}
if len(proxy.Reference) > 0 {
v.reference = proxy.Reference
return nil
}
v.schemas = proxy.Schemas
v.responses = proxy.Responses
v.parameters = proxy.Parameters
v.examples = proxy.Examples
v.requestBodies = proxy.RequestBodies
v.headers = proxy.Headers
v.securitySchemes = proxy.SecuritySchemes
v.links = proxy.Links
v.callbacks = proxy.Callbacks
return nil
}
func (v *components) QueryJSON(path string) (ret interface{}, ok bool) {
path = strings.TrimLeftFunc(path, func(r rune) bool { return r == '#' || r == '/' })
if path == "" {
return v, true
}
var frag string
if i := strings.Index(path, "/"); i > -1 {
frag = path[:i]
path = path[i+1:]
} else {
frag = path
path = ""
}
var target interface{}
switch frag {
case "schemas":
target = v.schemas
case "responses":
target = v.responses
case "parameters":
target = v.parameters
case "examples":
target = v.examples
case "requestBodies":
target = v.requestBodies
case "headers":
target = v.headers
case "securitySchemes":
target = v.securitySchemes
case "links":
target = v.links
case "callbacks":
target = v.callbacks
default:
return nil, false
}
if qj, ok := target.(QueryJSONer); ok {
return qj.QueryJSON(path)
}
if path == "" {
return target, true
}
return nil, false
}
// ComponentsFromJSON constructs a Components from JSON buffer. `dst` must
// be a pointer to `Components`
func ComponentsFromJSON(buf []byte, dst interface{}) error {
v, ok := dst.(*Components)
if !ok {
return errors.Errorf(`dst needs to be a pointer to Components, but got %T`, dst)
}
var tmp components
if err := json.Unmarshal(buf, &tmp); err != nil {
return errors.Wrap(err, `failed to unmarshal Components`)
}
*v = &tmp
return nil
}