| 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 |
type PathItemProps struct { |
| 27 |
Get *Operation `json:"get,omitempty"` |
| 28 |
Put *Operation `json:"put,omitempty"` |
| 29 |
Post *Operation `json:"post,omitempty"` |
| 30 |
Delete *Operation `json:"delete,omitempty"` |
| 31 |
Options *Operation `json:"options,omitempty"` |
| 32 |
Head *Operation `json:"head,omitempty"` |
| 33 |
Patch *Operation `json:"patch,omitempty"` |
| 34 |
Parameters []Parameter `json:"parameters,omitempty"` |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
type PathItem struct { |
| 44 |
Refable |
| 45 |
VendorExtensible |
| 46 |
PathItemProps |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
func (p *PathItem) UnmarshalJSON(data []byte) error { |
| 51 |
if internal.UseOptimizedJSONUnmarshaling { |
| 52 |
return jsonv2.Unmarshal(data, p) |
| 53 |
} |
| 54 |
|
| 55 |
if err := json.Unmarshal(data, &p.Refable); err != nil { |
| 56 |
return err |
| 57 |
} |
| 58 |
if err := json.Unmarshal(data, &p.VendorExtensible); err != nil { |
| 59 |
return err |
| 60 |
} |
| 61 |
return json.Unmarshal(data, &p.PathItemProps) |
| 62 |
} |
| 63 |
|
| 64 |
func (p *PathItem) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error { |
| 65 |
var x struct { |
| 66 |
Extensions |
| 67 |
PathItemProps |
| 68 |
} |
| 69 |
|
| 70 |
if err := opts.UnmarshalNext(dec, &x); err != nil { |
| 71 |
return err |
| 72 |
} |
| 73 |
if err := p.Refable.Ref.fromMap(x.Extensions); err != nil { |
| 74 |
return err |
| 75 |
} |
| 76 |
p.Extensions = internal.SanitizeExtensions(x.Extensions) |
| 77 |
p.PathItemProps = x.PathItemProps |
| 78 |
|
| 79 |
return nil |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
func (p PathItem) MarshalJSON() ([]byte, error) { |
| 84 |
if internal.UseOptimizedJSONMarshaling { |
| 85 |
return internal.DeterministicMarshal(p) |
| 86 |
} |
| 87 |
b3, err := json.Marshal(p.Refable) |
| 88 |
if err != nil { |
| 89 |
return nil, err |
| 90 |
} |
| 91 |
b4, err := json.Marshal(p.VendorExtensible) |
| 92 |
if err != nil { |
| 93 |
return nil, err |
| 94 |
} |
| 95 |
b5, err := json.Marshal(p.PathItemProps) |
| 96 |
if err != nil { |
| 97 |
return nil, err |
| 98 |
} |
| 99 |
concated := swag.ConcatJSON(b3, b4, b5) |
| 100 |
return concated, nil |
| 101 |
} |
| 102 |
|
| 103 |
func (p PathItem) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error { |
| 104 |
var x struct { |
| 105 |
Ref string `json:"$ref,omitempty"` |
| 106 |
Extensions |
| 107 |
PathItemProps |
| 108 |
} |
| 109 |
x.Ref = p.Refable.Ref.String() |
| 110 |
x.Extensions = internal.SanitizeExtensions(p.Extensions) |
| 111 |
x.PathItemProps = p.PathItemProps |
| 112 |
return opts.MarshalNext(enc, x) |
| 113 |
} |