| 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 |
type ExternalDocumentation struct { |
| 29 |
ExternalDocumentationProps |
| 30 |
spec.VendorExtensible |
| 31 |
} |
| 32 |
|
| 33 |
type ExternalDocumentationProps struct { |
| 34 |
|
| 35 |
Description string `json:"description,omitempty"` |
| 36 |
|
| 37 |
URL string `json:"url"` |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
func (e *ExternalDocumentation) MarshalJSON() ([]byte, error) { |
| 42 |
if internal.UseOptimizedJSONMarshalingV3 { |
| 43 |
return internal.DeterministicMarshal(e) |
| 44 |
} |
| 45 |
b1, err := json.Marshal(e.ExternalDocumentationProps) |
| 46 |
if err != nil { |
| 47 |
return nil, err |
| 48 |
} |
| 49 |
b2, err := json.Marshal(e.VendorExtensible) |
| 50 |
if err != nil { |
| 51 |
return nil, err |
| 52 |
} |
| 53 |
return swag.ConcatJSON(b1, b2), nil |
| 54 |
} |
| 55 |
|
| 56 |
func (e *ExternalDocumentation) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error { |
| 57 |
var x struct { |
| 58 |
ExternalDocumentationProps `json:",inline"` |
| 59 |
spec.Extensions |
| 60 |
} |
| 61 |
x.Extensions = internal.SanitizeExtensions(e.Extensions) |
| 62 |
x.ExternalDocumentationProps = e.ExternalDocumentationProps |
| 63 |
return opts.MarshalNext(enc, x) |
| 64 |
} |
| 65 |
|
| 66 |
func (e *ExternalDocumentation) UnmarshalJSON(data []byte) error { |
| 67 |
if internal.UseOptimizedJSONUnmarshalingV3 { |
| 68 |
return jsonv2.Unmarshal(data, e) |
| 69 |
} |
| 70 |
if err := json.Unmarshal(data, &e.ExternalDocumentationProps); err != nil { |
| 71 |
return err |
| 72 |
} |
| 73 |
if err := json.Unmarshal(data, &e.VendorExtensible); err != nil { |
| 74 |
return err |
| 75 |
} |
| 76 |
return nil |
| 77 |
} |
| 78 |
|
| 79 |
func (e *ExternalDocumentation) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error { |
| 80 |
var x struct { |
| 81 |
spec.Extensions |
| 82 |
ExternalDocumentationProps |
| 83 |
} |
| 84 |
if err := opts.UnmarshalNext(dec, &x); err != nil { |
| 85 |
return err |
| 86 |
} |
| 87 |
e.Extensions = internal.SanitizeExtensions(x.Extensions) |
| 88 |
e.ExternalDocumentationProps = x.ExternalDocumentationProps |
| 89 |
return nil |
| 90 |
} |