| 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 Operation struct { |
| 32 |
OperationProps |
| 33 |
spec.VendorExtensible |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
func (o *Operation) MarshalJSON() ([]byte, error) { |
| 38 |
if internal.UseOptimizedJSONMarshalingV3 { |
| 39 |
return internal.DeterministicMarshal(o) |
| 40 |
} |
| 41 |
b1, err := json.Marshal(o.OperationProps) |
| 42 |
if err != nil { |
| 43 |
return nil, err |
| 44 |
} |
| 45 |
b2, err := json.Marshal(o.VendorExtensible) |
| 46 |
if err != nil { |
| 47 |
return nil, err |
| 48 |
} |
| 49 |
return swag.ConcatJSON(b1, b2), nil |
| 50 |
} |
| 51 |
|
| 52 |
func (o *Operation) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error { |
| 53 |
var x struct { |
| 54 |
spec.Extensions |
| 55 |
OperationProps operationPropsOmitZero `json:",inline"` |
| 56 |
} |
| 57 |
x.Extensions = internal.SanitizeExtensions(o.Extensions) |
| 58 |
x.OperationProps = operationPropsOmitZero(o.OperationProps) |
| 59 |
return opts.MarshalNext(enc, x) |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
func (o *Operation) UnmarshalJSON(data []byte) error { |
| 64 |
if internal.UseOptimizedJSONUnmarshalingV3 { |
| 65 |
return jsonv2.Unmarshal(data, o) |
| 66 |
} |
| 67 |
if err := json.Unmarshal(data, &o.OperationProps); err != nil { |
| 68 |
return err |
| 69 |
} |
| 70 |
return json.Unmarshal(data, &o.VendorExtensible) |
| 71 |
} |
| 72 |
|
| 73 |
func (o *Operation) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error { |
| 74 |
var x struct { |
| 75 |
spec.Extensions |
| 76 |
OperationProps |
| 77 |
} |
| 78 |
if err := opts.UnmarshalNext(dec, &x); err != nil { |
| 79 |
return err |
| 80 |
} |
| 81 |
o.Extensions = internal.SanitizeExtensions(x.Extensions) |
| 82 |
o.OperationProps = x.OperationProps |
| 83 |
return nil |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
type OperationProps struct { |
| 88 |
|
| 89 |
Tags []string `json:"tags,omitempty"` |
| 90 |
|
| 91 |
Summary string `json:"summary,omitempty"` |
| 92 |
|
| 93 |
Description string `json:"description,omitempty"` |
| 94 |
|
| 95 |
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"` |
| 96 |
|
| 97 |
OperationId string `json:"operationId,omitempty"` |
| 98 |
|
| 99 |
Parameters []*Parameter `json:"parameters,omitempty"` |
| 100 |
|
| 101 |
RequestBody *RequestBody `json:"requestBody,omitempty"` |
| 102 |
|
| 103 |
Responses *Responses `json:"responses,omitempty"` |
| 104 |
|
| 105 |
Deprecated bool `json:"deprecated,omitempty"` |
| 106 |
|
| 107 |
SecurityRequirement []map[string][]string `json:"security,omitempty"` |
| 108 |
|
| 109 |
Servers []*Server `json:"servers,omitempty"` |
| 110 |
} |
| 111 |
|
| 112 |
type operationPropsOmitZero struct { |
| 113 |
Tags []string `json:"tags,omitempty"` |
| 114 |
Summary string `json:"summary,omitempty"` |
| 115 |
Description string `json:"description,omitempty"` |
| 116 |
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitzero"` |
| 117 |
OperationId string `json:"operationId,omitempty"` |
| 118 |
Parameters []*Parameter `json:"parameters,omitempty"` |
| 119 |
RequestBody *RequestBody `json:"requestBody,omitzero"` |
| 120 |
Responses *Responses `json:"responses,omitzero"` |
| 121 |
Deprecated bool `json:"deprecated,omitzero"` |
| 122 |
SecurityRequirement []map[string][]string `json:"security,omitempty"` |
| 123 |
Servers []*Server `json:"servers,omitempty"` |
| 124 |
} |