-
Notifications
You must be signed in to change notification settings - Fork 2
/
security_requirement_json_gen.go
97 lines (83 loc) · 2.19 KB
/
security_requirement_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
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 securityRequirementMarshalProxy struct {
Reference string `json:"$ref,omitempty"`
Schemes StringListMap `json:""`
}
type securityRequirementUnmarshalProxy struct {
Reference string `json:"$ref,omitempty"`
Schemes StringListMap `json:""`
}
func (v *securityRequirement) MarshalJSON() ([]byte, error) {
var proxy securityRequirementMarshalProxy
if len(v.reference) > 0 {
proxy.Reference = v.reference
return json.Marshal(proxy)
}
proxy.Schemes = v.schemes
return json.Marshal(proxy)
}
func (v *securityRequirement) UnmarshalJSON(data []byte) error {
var proxy securityRequirementUnmarshalProxy
if err := json.Unmarshal(data, &proxy); err != nil {
return errors.Wrapf(err, `failed to unmarshal securityRequirement`)
}
if len(proxy.Reference) > 0 {
v.reference = proxy.Reference
return nil
}
v.schemes = proxy.Schemes
return nil
}
func (v *securityRequirement) 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 "schemes":
target = v.schemes
default:
return nil, false
}
if qj, ok := target.(QueryJSONer); ok {
return qj.QueryJSON(path)
}
if path == "" {
return target, true
}
return nil, false
}
// SecurityRequirementFromJSON constructs a SecurityRequirement from JSON buffer. `dst` must
// be a pointer to `SecurityRequirement`
func SecurityRequirementFromJSON(buf []byte, dst interface{}) error {
v, ok := dst.(*SecurityRequirement)
if !ok {
return errors.Errorf(`dst needs to be a pointer to SecurityRequirement, but got %T`, dst)
}
var tmp securityRequirement
if err := json.Unmarshal(buf, &tmp); err != nil {
return errors.Wrap(err, `failed to unmarshal SecurityRequirement`)
}
*v = &tmp
return nil
}