github.com/minio/console@v1.4.1/models/set_config_request.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 "github.com/go-openapi/validate" 33 ) 34 35 // SetConfigRequest set config request 36 // 37 // swagger:model setConfigRequest 38 type SetConfigRequest struct { 39 40 // Used if configuration is an event notification's target 41 ArnResourceID string `json:"arn_resource_id,omitempty"` 42 43 // key values 44 // Required: true 45 // Min Items: 1 46 KeyValues []*ConfigurationKV `json:"key_values"` 47 } 48 49 // Validate validates this set config request 50 func (m *SetConfigRequest) Validate(formats strfmt.Registry) error { 51 var res []error 52 53 if err := m.validateKeyValues(formats); err != nil { 54 res = append(res, err) 55 } 56 57 if len(res) > 0 { 58 return errors.CompositeValidationError(res...) 59 } 60 return nil 61 } 62 63 func (m *SetConfigRequest) validateKeyValues(formats strfmt.Registry) error { 64 65 if err := validate.Required("key_values", "body", m.KeyValues); err != nil { 66 return err 67 } 68 69 iKeyValuesSize := int64(len(m.KeyValues)) 70 71 if err := validate.MinItems("key_values", "body", iKeyValuesSize, 1); err != nil { 72 return err 73 } 74 75 for i := 0; i < len(m.KeyValues); i++ { 76 if swag.IsZero(m.KeyValues[i]) { // not required 77 continue 78 } 79 80 if m.KeyValues[i] != nil { 81 if err := m.KeyValues[i].Validate(formats); err != nil { 82 if ve, ok := err.(*errors.Validation); ok { 83 return ve.ValidateName("key_values" + "." + strconv.Itoa(i)) 84 } else if ce, ok := err.(*errors.CompositeError); ok { 85 return ce.ValidateName("key_values" + "." + strconv.Itoa(i)) 86 } 87 return err 88 } 89 } 90 91 } 92 93 return nil 94 } 95 96 // ContextValidate validate this set config request based on the context it is used 97 func (m *SetConfigRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 98 var res []error 99 100 if err := m.contextValidateKeyValues(ctx, formats); err != nil { 101 res = append(res, err) 102 } 103 104 if len(res) > 0 { 105 return errors.CompositeValidationError(res...) 106 } 107 return nil 108 } 109 110 func (m *SetConfigRequest) contextValidateKeyValues(ctx context.Context, formats strfmt.Registry) error { 111 112 for i := 0; i < len(m.KeyValues); i++ { 113 114 if m.KeyValues[i] != nil { 115 116 if swag.IsZero(m.KeyValues[i]) { // not required 117 return nil 118 } 119 120 if err := m.KeyValues[i].ContextValidate(ctx, formats); err != nil { 121 if ve, ok := err.(*errors.Validation); ok { 122 return ve.ValidateName("key_values" + "." + strconv.Itoa(i)) 123 } else if ce, ok := err.(*errors.CompositeError); ok { 124 return ce.ValidateName("key_values" + "." + strconv.Itoa(i)) 125 } 126 return err 127 } 128 } 129 130 } 131 132 return nil 133 } 134 135 // MarshalBinary interface implementation 136 func (m *SetConfigRequest) MarshalBinary() ([]byte, error) { 137 if m == nil { 138 return nil, nil 139 } 140 return swag.WriteJSON(m) 141 } 142 143 // UnmarshalBinary interface implementation 144 func (m *SetConfigRequest) UnmarshalBinary(b []byte) error { 145 var res SetConfigRequest 146 if err := swag.ReadJSON(b, &res); err != nil { 147 return err 148 } 149 *m = res 150 return nil 151 }