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