| 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 RequestBody struct { |
| 32 |
spec.Refable |
| 33 |
RequestBodyProps |
| 34 |
spec.VendorExtensible |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
func (r *RequestBody) MarshalJSON() ([]byte, error) { |
| 39 |
if internal.UseOptimizedJSONMarshalingV3 { |
| 40 |
return internal.DeterministicMarshal(r) |
| 41 |
} |
| 42 |
b1, err := json.Marshal(r.Refable) |
| 43 |
if err != nil { |
| 44 |
return nil, err |
| 45 |
} |
| 46 |
b2, err := json.Marshal(r.RequestBodyProps) |
| 47 |
if err != nil { |
| 48 |
return nil, err |
| 49 |
} |
| 50 |
b3, err := json.Marshal(r.VendorExtensible) |
| 51 |
if err != nil { |
| 52 |
return nil, err |
| 53 |
} |
| 54 |
return swag.ConcatJSON(b1, b2, b3), nil |
| 55 |
} |
| 56 |
|
| 57 |
func (r *RequestBody) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error { |
| 58 |
var x struct { |
| 59 |
Ref string `json:"$ref,omitempty"` |
| 60 |
RequestBodyProps requestBodyPropsOmitZero `json:",inline"` |
| 61 |
spec.Extensions |
| 62 |
} |
| 63 |
x.Ref = r.Refable.Ref.String() |
| 64 |
x.Extensions = internal.SanitizeExtensions(r.Extensions) |
| 65 |
x.RequestBodyProps = requestBodyPropsOmitZero(r.RequestBodyProps) |
| 66 |
return opts.MarshalNext(enc, x) |
| 67 |
} |
| 68 |
|
| 69 |
func (r *RequestBody) UnmarshalJSON(data []byte) error { |
| 70 |
if internal.UseOptimizedJSONUnmarshalingV3 { |
| 71 |
return jsonv2.Unmarshal(data, r) |
| 72 |
} |
| 73 |
if err := json.Unmarshal(data, &r.Refable); err != nil { |
| 74 |
return err |
| 75 |
} |
| 76 |
if err := json.Unmarshal(data, &r.RequestBodyProps); err != nil { |
| 77 |
return err |
| 78 |
} |
| 79 |
if err := json.Unmarshal(data, &r.VendorExtensible); err != nil { |
| 80 |
return err |
| 81 |
} |
| 82 |
return nil |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
type RequestBodyProps struct { |
| 87 |
|
| 88 |
Description string `json:"description,omitempty"` |
| 89 |
|
| 90 |
Content map[string]*MediaType `json:"content,omitempty"` |
| 91 |
|
| 92 |
Required bool `json:"required,omitempty"` |
| 93 |
} |
| 94 |
|
| 95 |
type requestBodyPropsOmitZero struct { |
| 96 |
Description string `json:"description,omitempty"` |
| 97 |
Content map[string]*MediaType `json:"content,omitempty"` |
| 98 |
Required bool `json:"required,omitzero"` |
| 99 |
} |
| 100 |
|
| 101 |
func (r *RequestBody) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error { |
| 102 |
var x struct { |
| 103 |
spec.Extensions |
| 104 |
RequestBodyProps |
| 105 |
} |
| 106 |
if err := opts.UnmarshalNext(dec, &x); err != nil { |
| 107 |
return err |
| 108 |
} |
| 109 |
if err := internal.JSONRefFromMap(&r.Ref.Ref, x.Extensions); err != nil { |
| 110 |
return err |
| 111 |
} |
| 112 |
r.Extensions = internal.SanitizeExtensions(x.Extensions) |
| 113 |
r.RequestBodyProps = x.RequestBodyProps |
| 114 |
return nil |
| 115 |
} |