| 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 |
const ( |
| 26 |
jsonArray = "array" |
| 27 |
) |
| 28 |
|
| 29 |
|
| 30 |
type HeaderProps struct { |
| 31 |
Description string `json:"description,omitempty"` |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
type Header struct { |
| 38 |
CommonValidations |
| 39 |
SimpleSchema |
| 40 |
VendorExtensible |
| 41 |
HeaderProps |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
func (h Header) MarshalJSON() ([]byte, error) { |
| 46 |
if internal.UseOptimizedJSONMarshaling { |
| 47 |
return internal.DeterministicMarshal(h) |
| 48 |
} |
| 49 |
b1, err := json.Marshal(h.CommonValidations) |
| 50 |
if err != nil { |
| 51 |
return nil, err |
| 52 |
} |
| 53 |
b2, err := json.Marshal(h.SimpleSchema) |
| 54 |
if err != nil { |
| 55 |
return nil, err |
| 56 |
} |
| 57 |
b3, err := json.Marshal(h.HeaderProps) |
| 58 |
if err != nil { |
| 59 |
return nil, err |
| 60 |
} |
| 61 |
b4, err := json.Marshal(h.VendorExtensible) |
| 62 |
if err != nil { |
| 63 |
return nil, err |
| 64 |
} |
| 65 |
return swag.ConcatJSON(b1, b2, b3, b4), nil |
| 66 |
} |
| 67 |
|
| 68 |
func (h Header) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error { |
| 69 |
var x struct { |
| 70 |
CommonValidations commonValidationsOmitZero `json:",inline"` |
| 71 |
SimpleSchema simpleSchemaOmitZero `json:",inline"` |
| 72 |
Extensions |
| 73 |
HeaderProps |
| 74 |
} |
| 75 |
x.CommonValidations = commonValidationsOmitZero(h.CommonValidations) |
| 76 |
x.SimpleSchema = simpleSchemaOmitZero(h.SimpleSchema) |
| 77 |
x.Extensions = internal.SanitizeExtensions(h.Extensions) |
| 78 |
x.HeaderProps = h.HeaderProps |
| 79 |
return opts.MarshalNext(enc, x) |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
func (h *Header) UnmarshalJSON(data []byte) error { |
| 84 |
if internal.UseOptimizedJSONUnmarshaling { |
| 85 |
return jsonv2.Unmarshal(data, h) |
| 86 |
} |
| 87 |
|
| 88 |
if err := json.Unmarshal(data, &h.CommonValidations); err != nil { |
| 89 |
return err |
| 90 |
} |
| 91 |
if err := json.Unmarshal(data, &h.SimpleSchema); err != nil { |
| 92 |
return err |
| 93 |
} |
| 94 |
if err := json.Unmarshal(data, &h.VendorExtensible); err != nil { |
| 95 |
return err |
| 96 |
} |
| 97 |
return json.Unmarshal(data, &h.HeaderProps) |
| 98 |
} |
| 99 |
|
| 100 |
func (h *Header) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error { |
| 101 |
var x struct { |
| 102 |
CommonValidations |
| 103 |
SimpleSchema |
| 104 |
Extensions |
| 105 |
HeaderProps |
| 106 |
} |
| 107 |
|
| 108 |
if err := opts.UnmarshalNext(dec, &x); err != nil { |
| 109 |
return err |
| 110 |
} |
| 111 |
|
| 112 |
h.CommonValidations = x.CommonValidations |
| 113 |
h.SimpleSchema = x.SimpleSchema |
| 114 |
h.Extensions = internal.SanitizeExtensions(x.Extensions) |
| 115 |
h.HeaderProps = x.HeaderProps |
| 116 |
|
| 117 |
return nil |
| 118 |
} |