| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package spec |
| 16 |
|
| 17 |
import ( |
| 18 |
"encoding/json" |
| 19 |
|
| 20 |
"github.com/go-openapi/swag" |
| 21 |
"k8s.io/kube-openapi/pkg/internal" |
| 22 |
jsonv2 "k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json" |
| 23 |
) |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
type ParamProps struct { |
| 31 |
Description string `json:"description,omitempty"` |
| 32 |
Name string `json:"name,omitempty"` |
| 33 |
In string `json:"in,omitempty"` |
| 34 |
Required bool `json:"required,omitempty"` |
| 35 |
Schema *Schema `json:"schema,omitempty"` |
| 36 |
AllowEmptyValue bool `json:"allowEmptyValue,omitempty"` |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
type paramPropsOmitZero struct { |
| 42 |
Description string `json:"description,omitempty"` |
| 43 |
Name string `json:"name,omitempty"` |
| 44 |
In string `json:"in,omitempty"` |
| 45 |
Required bool `json:"required,omitzero"` |
| 46 |
Schema *Schema `json:"schema,omitzero"` |
| 47 |
AllowEmptyValue bool `json:"allowEmptyValue,omitzero"` |
| 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 |
type Parameter struct { |
| 82 |
Refable |
| 83 |
CommonValidations |
| 84 |
SimpleSchema |
| 85 |
VendorExtensible |
| 86 |
ParamProps |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
func (p *Parameter) UnmarshalJSON(data []byte) error { |
| 91 |
if internal.UseOptimizedJSONUnmarshaling { |
| 92 |
return jsonv2.Unmarshal(data, p) |
| 93 |
} |
| 94 |
|
| 95 |
if err := json.Unmarshal(data, &p.CommonValidations); err != nil { |
| 96 |
return err |
| 97 |
} |
| 98 |
if err := json.Unmarshal(data, &p.Refable); err != nil { |
| 99 |
return err |
| 100 |
} |
| 101 |
if err := json.Unmarshal(data, &p.SimpleSchema); err != nil { |
| 102 |
return err |
| 103 |
} |
| 104 |
if err := json.Unmarshal(data, &p.VendorExtensible); err != nil { |
| 105 |
return err |
| 106 |
} |
| 107 |
return json.Unmarshal(data, &p.ParamProps) |
| 108 |
} |
| 109 |
|
| 110 |
func (p *Parameter) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error { |
| 111 |
var x struct { |
| 112 |
CommonValidations |
| 113 |
SimpleSchema |
| 114 |
Extensions |
| 115 |
ParamProps |
| 116 |
} |
| 117 |
if err := opts.UnmarshalNext(dec, &x); err != nil { |
| 118 |
return err |
| 119 |
} |
| 120 |
if err := p.Refable.Ref.fromMap(x.Extensions); err != nil { |
| 121 |
return err |
| 122 |
} |
| 123 |
p.CommonValidations = x.CommonValidations |
| 124 |
p.SimpleSchema = x.SimpleSchema |
| 125 |
p.Extensions = internal.SanitizeExtensions(x.Extensions) |
| 126 |
p.ParamProps = x.ParamProps |
| 127 |
return nil |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
func (p Parameter) MarshalJSON() ([]byte, error) { |
| 132 |
if internal.UseOptimizedJSONMarshaling { |
| 133 |
return internal.DeterministicMarshal(p) |
| 134 |
} |
| 135 |
b1, err := json.Marshal(p.CommonValidations) |
| 136 |
if err != nil { |
| 137 |
return nil, err |
| 138 |
} |
| 139 |
b2, err := json.Marshal(p.SimpleSchema) |
| 140 |
if err != nil { |
| 141 |
return nil, err |
| 142 |
} |
| 143 |
b3, err := json.Marshal(p.Refable) |
| 144 |
if err != nil { |
| 145 |
return nil, err |
| 146 |
} |
| 147 |
b4, err := json.Marshal(p.VendorExtensible) |
| 148 |
if err != nil { |
| 149 |
return nil, err |
| 150 |
} |
| 151 |
b5, err := json.Marshal(p.ParamProps) |
| 152 |
if err != nil { |
| 153 |
return nil, err |
| 154 |
} |
| 155 |
return swag.ConcatJSON(b3, b1, b2, b4, b5), nil |
| 156 |
} |
| 157 |
|
| 158 |
func (p Parameter) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error { |
| 159 |
var x struct { |
| 160 |
CommonValidations commonValidationsOmitZero `json:",inline"` |
| 161 |
SimpleSchema simpleSchemaOmitZero `json:",inline"` |
| 162 |
ParamProps paramPropsOmitZero `json:",inline"` |
| 163 |
Ref string `json:"$ref,omitempty"` |
| 164 |
Extensions |
| 165 |
} |
| 166 |
x.CommonValidations = commonValidationsOmitZero(p.CommonValidations) |
| 167 |
x.SimpleSchema = simpleSchemaOmitZero(p.SimpleSchema) |
| 168 |
x.Extensions = internal.SanitizeExtensions(p.Extensions) |
| 169 |
x.ParamProps = paramPropsOmitZero(p.ParamProps) |
| 170 |
x.Ref = p.Refable.Ref.String() |
| 171 |
return opts.MarshalNext(enc, x) |
| 172 |
} |