github.com/minio/console@v1.4.1/models/widget.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 // This file is part of MinIO Console Server 4 // Copyright (c) 2023 MinIO, Inc. 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU Affero General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU Affero General Public License for more details. 15 // 16 // You should have received a copy of the GNU Affero General Public License 17 // along with this program. If not, see <http://www.gnu.org/licenses/>. 18 // 19 20 package models 21 22 // This file was generated by the swagger tool. 23 // Editing this file might prove futile when you re-run the swagger generate command 24 25 import ( 26 "context" 27 "strconv" 28 29 "github.com/go-openapi/errors" 30 "github.com/go-openapi/strfmt" 31 "github.com/go-openapi/swag" 32 ) 33 34 // Widget widget 35 // 36 // swagger:model widget 37 type Widget struct { 38 39 // id 40 ID int32 `json:"id,omitempty"` 41 42 // options 43 Options *WidgetOptions `json:"options,omitempty"` 44 45 // targets 46 Targets []*ResultTarget `json:"targets"` 47 48 // title 49 Title string `json:"title,omitempty"` 50 51 // type 52 Type string `json:"type,omitempty"` 53 } 54 55 // Validate validates this widget 56 func (m *Widget) Validate(formats strfmt.Registry) error { 57 var res []error 58 59 if err := m.validateOptions(formats); err != nil { 60 res = append(res, err) 61 } 62 63 if err := m.validateTargets(formats); err != nil { 64 res = append(res, err) 65 } 66 67 if len(res) > 0 { 68 return errors.CompositeValidationError(res...) 69 } 70 return nil 71 } 72 73 func (m *Widget) validateOptions(formats strfmt.Registry) error { 74 if swag.IsZero(m.Options) { // not required 75 return nil 76 } 77 78 if m.Options != nil { 79 if err := m.Options.Validate(formats); err != nil { 80 if ve, ok := err.(*errors.Validation); ok { 81 return ve.ValidateName("options") 82 } else if ce, ok := err.(*errors.CompositeError); ok { 83 return ce.ValidateName("options") 84 } 85 return err 86 } 87 } 88 89 return nil 90 } 91 92 func (m *Widget) validateTargets(formats strfmt.Registry) error { 93 if swag.IsZero(m.Targets) { // not required 94 return nil 95 } 96 97 for i := 0; i < len(m.Targets); i++ { 98 if swag.IsZero(m.Targets[i]) { // not required 99 continue 100 } 101 102 if m.Targets[i] != nil { 103 if err := m.Targets[i].Validate(formats); err != nil { 104 if ve, ok := err.(*errors.Validation); ok { 105 return ve.ValidateName("targets" + "." + strconv.Itoa(i)) 106 } else if ce, ok := err.(*errors.CompositeError); ok { 107 return ce.ValidateName("targets" + "." + strconv.Itoa(i)) 108 } 109 return err 110 } 111 } 112 113 } 114 115 return nil 116 } 117 118 // ContextValidate validate this widget based on the context it is used 119 func (m *Widget) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 120 var res []error 121 122 if err := m.contextValidateOptions(ctx, formats); err != nil { 123 res = append(res, err) 124 } 125 126 if err := m.contextValidateTargets(ctx, formats); err != nil { 127 res = append(res, err) 128 } 129 130 if len(res) > 0 { 131 return errors.CompositeValidationError(res...) 132 } 133 return nil 134 } 135 136 func (m *Widget) contextValidateOptions(ctx context.Context, formats strfmt.Registry) error { 137 138 if m.Options != nil { 139 140 if swag.IsZero(m.Options) { // not required 141 return nil 142 } 143 144 if err := m.Options.ContextValidate(ctx, formats); err != nil { 145 if ve, ok := err.(*errors.Validation); ok { 146 return ve.ValidateName("options") 147 } else if ce, ok := err.(*errors.CompositeError); ok { 148 return ce.ValidateName("options") 149 } 150 return err 151 } 152 } 153 154 return nil 155 } 156 157 func (m *Widget) contextValidateTargets(ctx context.Context, formats strfmt.Registry) error { 158 159 for i := 0; i < len(m.Targets); i++ { 160 161 if m.Targets[i] != nil { 162 163 if swag.IsZero(m.Targets[i]) { // not required 164 return nil 165 } 166 167 if err := m.Targets[i].ContextValidate(ctx, formats); err != nil { 168 if ve, ok := err.(*errors.Validation); ok { 169 return ve.ValidateName("targets" + "." + strconv.Itoa(i)) 170 } else if ce, ok := err.(*errors.CompositeError); ok { 171 return ce.ValidateName("targets" + "." + strconv.Itoa(i)) 172 } 173 return err 174 } 175 } 176 177 } 178 179 return nil 180 } 181 182 // MarshalBinary interface implementation 183 func (m *Widget) MarshalBinary() ([]byte, error) { 184 if m == nil { 185 return nil, nil 186 } 187 return swag.WriteJSON(m) 188 } 189 190 // UnmarshalBinary interface implementation 191 func (m *Widget) UnmarshalBinary(b []byte) error { 192 var res Widget 193 if err := swag.ReadJSON(b, &res); err != nil { 194 return err 195 } 196 *m = res 197 return nil 198 } 199 200 // WidgetOptions widget options 201 // 202 // swagger:model WidgetOptions 203 type WidgetOptions struct { 204 205 // reduce options 206 ReduceOptions *WidgetOptionsReduceOptions `json:"reduceOptions,omitempty"` 207 } 208 209 // Validate validates this widget options 210 func (m *WidgetOptions) Validate(formats strfmt.Registry) error { 211 var res []error 212 213 if err := m.validateReduceOptions(formats); err != nil { 214 res = append(res, err) 215 } 216 217 if len(res) > 0 { 218 return errors.CompositeValidationError(res...) 219 } 220 return nil 221 } 222 223 func (m *WidgetOptions) validateReduceOptions(formats strfmt.Registry) error { 224 if swag.IsZero(m.ReduceOptions) { // not required 225 return nil 226 } 227 228 if m.ReduceOptions != nil { 229 if err := m.ReduceOptions.Validate(formats); err != nil { 230 if ve, ok := err.(*errors.Validation); ok { 231 return ve.ValidateName("options" + "." + "reduceOptions") 232 } else if ce, ok := err.(*errors.CompositeError); ok { 233 return ce.ValidateName("options" + "." + "reduceOptions") 234 } 235 return err 236 } 237 } 238 239 return nil 240 } 241 242 // ContextValidate validate this widget options based on the context it is used 243 func (m *WidgetOptions) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 244 var res []error 245 246 if err := m.contextValidateReduceOptions(ctx, formats); err != nil { 247 res = append(res, err) 248 } 249 250 if len(res) > 0 { 251 return errors.CompositeValidationError(res...) 252 } 253 return nil 254 } 255 256 func (m *WidgetOptions) contextValidateReduceOptions(ctx context.Context, formats strfmt.Registry) error { 257 258 if m.ReduceOptions != nil { 259 260 if swag.IsZero(m.ReduceOptions) { // not required 261 return nil 262 } 263 264 if err := m.ReduceOptions.ContextValidate(ctx, formats); err != nil { 265 if ve, ok := err.(*errors.Validation); ok { 266 return ve.ValidateName("options" + "." + "reduceOptions") 267 } else if ce, ok := err.(*errors.CompositeError); ok { 268 return ce.ValidateName("options" + "." + "reduceOptions") 269 } 270 return err 271 } 272 } 273 274 return nil 275 } 276 277 // MarshalBinary interface implementation 278 func (m *WidgetOptions) MarshalBinary() ([]byte, error) { 279 if m == nil { 280 return nil, nil 281 } 282 return swag.WriteJSON(m) 283 } 284 285 // UnmarshalBinary interface implementation 286 func (m *WidgetOptions) UnmarshalBinary(b []byte) error { 287 var res WidgetOptions 288 if err := swag.ReadJSON(b, &res); err != nil { 289 return err 290 } 291 *m = res 292 return nil 293 } 294 295 // WidgetOptionsReduceOptions widget options reduce options 296 // 297 // swagger:model WidgetOptionsReduceOptions 298 type WidgetOptionsReduceOptions struct { 299 300 // calcs 301 Calcs []string `json:"calcs"` 302 } 303 304 // Validate validates this widget options reduce options 305 func (m *WidgetOptionsReduceOptions) Validate(formats strfmt.Registry) error { 306 return nil 307 } 308 309 // ContextValidate validates this widget options reduce options based on context it is used 310 func (m *WidgetOptionsReduceOptions) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 311 return nil 312 } 313 314 // MarshalBinary interface implementation 315 func (m *WidgetOptionsReduceOptions) MarshalBinary() ([]byte, error) { 316 if m == nil { 317 return nil, nil 318 } 319 return swag.WriteJSON(m) 320 } 321 322 // UnmarshalBinary interface implementation 323 func (m *WidgetOptionsReduceOptions) UnmarshalBinary(b []byte) error { 324 var res WidgetOptionsReduceOptions 325 if err := swag.ReadJSON(b, &res); err != nil { 326 return err 327 } 328 *m = res 329 return nil 330 }