...
1
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 Server struct {
29 ServerProps
30 spec.VendorExtensible
31 }
32
33 type ServerProps struct {
34
35 Description string `json:"description,omitempty"`
36
37 URL string `json:"url"`
38
39 Variables map[string]*ServerVariable `json:"variables,omitempty"`
40 }
41
42
43 func (s *Server) MarshalJSON() ([]byte, error) {
44 if internal.UseOptimizedJSONMarshalingV3 {
45 return internal.DeterministicMarshal(s)
46 }
47 b1, err := json.Marshal(s.ServerProps)
48 if err != nil {
49 return nil, err
50 }
51 b2, err := json.Marshal(s.VendorExtensible)
52 if err != nil {
53 return nil, err
54 }
55 return swag.ConcatJSON(b1, b2), nil
56 }
57
58 func (s *Server) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error {
59 var x struct {
60 ServerProps `json:",inline"`
61 spec.Extensions
62 }
63 x.Extensions = internal.SanitizeExtensions(s.Extensions)
64 x.ServerProps = s.ServerProps
65 return opts.MarshalNext(enc, x)
66 }
67
68 func (s *Server) UnmarshalJSON(data []byte) error {
69 if internal.UseOptimizedJSONUnmarshalingV3 {
70 return jsonv2.Unmarshal(data, s)
71 }
72
73 if err := json.Unmarshal(data, &s.ServerProps); err != nil {
74 return err
75 }
76 if err := json.Unmarshal(data, &s.VendorExtensible); err != nil {
77 return err
78 }
79 return nil
80 }
81
82 func (s *Server) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error {
83 var x struct {
84 spec.Extensions
85 ServerProps
86 }
87 if err := opts.UnmarshalNext(dec, &x); err != nil {
88 return err
89 }
90 s.Extensions = internal.SanitizeExtensions(x.Extensions)
91 s.ServerProps = x.ServerProps
92
93 return nil
94 }
95
96 type ServerVariable struct {
97 ServerVariableProps
98 spec.VendorExtensible
99 }
100
101 type ServerVariableProps struct {
102
103 Enum []string `json:"enum,omitempty"`
104
105 Default string `json:"default"`
106
107 Description string `json:"description,omitempty"`
108 }
109
110
111 func (s *ServerVariable) MarshalJSON() ([]byte, error) {
112 if internal.UseOptimizedJSONMarshalingV3 {
113 return internal.DeterministicMarshal(s)
114 }
115 b1, err := json.Marshal(s.ServerVariableProps)
116 if err != nil {
117 return nil, err
118 }
119 b2, err := json.Marshal(s.VendorExtensible)
120 if err != nil {
121 return nil, err
122 }
123 return swag.ConcatJSON(b1, b2), nil
124 }
125
126 func (s *ServerVariable) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error {
127 var x struct {
128 ServerVariableProps `json:",inline"`
129 spec.Extensions
130 }
131 x.Extensions = internal.SanitizeExtensions(s.Extensions)
132 x.ServerVariableProps = s.ServerVariableProps
133 return opts.MarshalNext(enc, x)
134 }
135
136 func (s *ServerVariable) UnmarshalJSON(data []byte) error {
137 if internal.UseOptimizedJSONUnmarshalingV3 {
138 return jsonv2.Unmarshal(data, s)
139 }
140 if err := json.Unmarshal(data, &s.ServerVariableProps); err != nil {
141 return err
142 }
143 if err := json.Unmarshal(data, &s.VendorExtensible); err != nil {
144 return err
145 }
146 return nil
147 }
148
149 func (s *ServerVariable) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error {
150 var x struct {
151 spec.Extensions
152 ServerVariableProps
153 }
154 if err := opts.UnmarshalNext(dec, &x); err != nil {
155 return err
156 }
157 s.Extensions = internal.SanitizeExtensions(x.Extensions)
158 s.ServerVariableProps = x.ServerVariableProps
159
160 return nil
161 }
162
View as plain text