| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package spec3 |
| 18 |
|
| 19 |
import ( |
| 20 |
"encoding/json" |
| 21 |
|
| 22 |
"github.com/go-openapi/swag" |
| 23 |
"k8s.io/kube-openapi/pkg/internal" |
| 24 |
jsonv2 "k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json" |
| 25 |
"k8s.io/kube-openapi/pkg/validation/spec" |
| 26 |
) |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
type Header struct { |
| 32 |
spec.Refable |
| 33 |
HeaderProps |
| 34 |
spec.VendorExtensible |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
func (h *Header) MarshalJSON() ([]byte, error) { |
| 39 |
if internal.UseOptimizedJSONMarshalingV3 { |
| 40 |
return internal.DeterministicMarshal(h) |
| 41 |
} |
| 42 |
b1, err := json.Marshal(h.Refable) |
| 43 |
if err != nil { |
| 44 |
return nil, err |
| 45 |
} |
| 46 |
b2, err := json.Marshal(h.HeaderProps) |
| 47 |
if err != nil { |
| 48 |
return nil, err |
| 49 |
} |
| 50 |
b3, err := json.Marshal(h.VendorExtensible) |
| 51 |
if err != nil { |
| 52 |
return nil, err |
| 53 |
} |
| 54 |
return swag.ConcatJSON(b1, b2, b3), nil |
| 55 |
} |
| 56 |
|
| 57 |
func (h *Header) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error { |
| 58 |
var x struct { |
| 59 |
Ref string `json:"$ref,omitempty"` |
| 60 |
HeaderProps headerPropsOmitZero `json:",inline"` |
| 61 |
spec.Extensions |
| 62 |
} |
| 63 |
x.Ref = h.Refable.Ref.String() |
| 64 |
x.Extensions = internal.SanitizeExtensions(h.Extensions) |
| 65 |
x.HeaderProps = headerPropsOmitZero(h.HeaderProps) |
| 66 |
return opts.MarshalNext(enc, x) |
| 67 |
} |
| 68 |
|
| 69 |
func (h *Header) UnmarshalJSON(data []byte) error { |
| 70 |
if internal.UseOptimizedJSONUnmarshalingV3 { |
| 71 |
return jsonv2.Unmarshal(data, h) |
| 72 |
} |
| 73 |
if err := json.Unmarshal(data, &h.Refable); err != nil { |
| 74 |
return err |
| 75 |
} |
| 76 |
if err := json.Unmarshal(data, &h.HeaderProps); err != nil { |
| 77 |
return err |
| 78 |
} |
| 79 |
if err := json.Unmarshal(data, &h.VendorExtensible); err != nil { |
| 80 |
return err |
| 81 |
} |
| 82 |
|
| 83 |
return nil |
| 84 |
} |
| 85 |
|
| 86 |
func (h *Header) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error { |
| 87 |
var x struct { |
| 88 |
spec.Extensions |
| 89 |
HeaderProps |
| 90 |
} |
| 91 |
if err := opts.UnmarshalNext(dec, &x); err != nil { |
| 92 |
return err |
| 93 |
} |
| 94 |
if err := internal.JSONRefFromMap(&h.Ref.Ref, x.Extensions); err != nil { |
| 95 |
return err |
| 96 |
} |
| 97 |
h.Extensions = internal.SanitizeExtensions(x.Extensions) |
| 98 |
h.HeaderProps = x.HeaderProps |
| 99 |
return nil |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
type HeaderProps struct { |
| 104 |
|
| 105 |
Description string `json:"description,omitempty"` |
| 106 |
|
| 107 |
Required bool `json:"required,omitempty"` |
| 108 |
|
| 109 |
Deprecated bool `json:"deprecated,omitempty"` |
| 110 |
|
| 111 |
AllowEmptyValue bool `json:"allowEmptyValue,omitempty"` |
| 112 |
|
| 113 |
Style string `json:"style,omitempty"` |
| 114 |
|
| 115 |
Explode bool `json:"explode,omitempty"` |
| 116 |
|
| 117 |
AllowReserved bool `json:"allowReserved,omitempty"` |
| 118 |
|
| 119 |
Schema *spec.Schema `json:"schema,omitempty"` |
| 120 |
|
| 121 |
Content map[string]*MediaType `json:"content,omitempty"` |
| 122 |
|
| 123 |
Example interface{} `json:"example,omitempty"` |
| 124 |
|
| 125 |
Examples map[string]*Example `json:"examples,omitempty"` |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
type headerPropsOmitZero struct { |
| 131 |
Description string `json:"description,omitempty"` |
| 132 |
Required bool `json:"required,omitzero"` |
| 133 |
Deprecated bool `json:"deprecated,omitzero"` |
| 134 |
AllowEmptyValue bool `json:"allowEmptyValue,omitzero"` |
| 135 |
Style string `json:"style,omitempty"` |
| 136 |
Explode bool `json:"explode,omitzero"` |
| 137 |
AllowReserved bool `json:"allowReserved,omitzero"` |
| 138 |
Schema *spec.Schema `json:"schema,omitzero"` |
| 139 |
Content map[string]*MediaType `json:"content,omitempty"` |
| 140 |
Example interface{} `json:"example,omitempty"` |
| 141 |
Examples map[string]*Example `json:"examples,omitempty"` |
| 142 |
} |