Serge Bazanski | cc25bdf | 2018-10-25 14:02:58 +0200 | [diff] [blame] | 1 | // Code generated by go-swagger; DO NOT EDIT. |
| 2 | |
| 3 | // Copyright 2018 The go-netbox Authors. |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | package models |
| 18 | |
| 19 | // This file was generated by the swagger tool. |
| 20 | // Editing this file might prove futile when you re-run the swagger generate command |
| 21 | |
| 22 | import ( |
| 23 | "strconv" |
| 24 | |
| 25 | strfmt "github.com/go-openapi/strfmt" |
| 26 | |
| 27 | "github.com/go-openapi/errors" |
| 28 | "github.com/go-openapi/swag" |
| 29 | "github.com/go-openapi/validate" |
| 30 | ) |
| 31 | |
| 32 | // RackReservation rack reservation |
| 33 | // swagger:model RackReservation |
| 34 | type RackReservation struct { |
| 35 | |
| 36 | // Created |
| 37 | // Read Only: true |
| 38 | Created strfmt.DateTime `json:"created,omitempty"` |
| 39 | |
| 40 | // Description |
| 41 | // Required: true |
| 42 | // Max Length: 100 |
| 43 | Description *string `json:"description"` |
| 44 | |
| 45 | // ID |
| 46 | // Read Only: true |
| 47 | ID int64 `json:"id,omitempty"` |
| 48 | |
| 49 | // rack |
| 50 | // Required: true |
| 51 | Rack *NestedRack `json:"rack"` |
| 52 | |
| 53 | // tenant |
| 54 | // Required: true |
| 55 | Tenant *NestedTenant `json:"tenant"` |
| 56 | |
| 57 | // units |
| 58 | // Required: true |
| 59 | Units []*int64 `json:"units"` |
| 60 | |
| 61 | // user |
| 62 | // Required: true |
| 63 | User *NestedUser `json:"user"` |
| 64 | } |
| 65 | |
| 66 | // Validate validates this rack reservation |
| 67 | func (m *RackReservation) Validate(formats strfmt.Registry) error { |
| 68 | var res []error |
| 69 | |
| 70 | if err := m.validateDescription(formats); err != nil { |
| 71 | // prop |
| 72 | res = append(res, err) |
| 73 | } |
| 74 | |
| 75 | if err := m.validateRack(formats); err != nil { |
| 76 | // prop |
| 77 | res = append(res, err) |
| 78 | } |
| 79 | |
| 80 | if err := m.validateTenant(formats); err != nil { |
| 81 | // prop |
| 82 | res = append(res, err) |
| 83 | } |
| 84 | |
| 85 | if err := m.validateUnits(formats); err != nil { |
| 86 | // prop |
| 87 | res = append(res, err) |
| 88 | } |
| 89 | |
| 90 | if err := m.validateUser(formats); err != nil { |
| 91 | // prop |
| 92 | res = append(res, err) |
| 93 | } |
| 94 | |
| 95 | if len(res) > 0 { |
| 96 | return errors.CompositeValidationError(res...) |
| 97 | } |
| 98 | return nil |
| 99 | } |
| 100 | |
| 101 | func (m *RackReservation) validateDescription(formats strfmt.Registry) error { |
| 102 | |
| 103 | if err := validate.Required("description", "body", m.Description); err != nil { |
| 104 | return err |
| 105 | } |
| 106 | |
| 107 | if err := validate.MaxLength("description", "body", string(*m.Description), 100); err != nil { |
| 108 | return err |
| 109 | } |
| 110 | |
| 111 | return nil |
| 112 | } |
| 113 | |
| 114 | func (m *RackReservation) validateRack(formats strfmt.Registry) error { |
| 115 | |
| 116 | if err := validate.Required("rack", "body", m.Rack); err != nil { |
| 117 | return err |
| 118 | } |
| 119 | |
| 120 | if m.Rack != nil { |
| 121 | |
| 122 | if err := m.Rack.Validate(formats); err != nil { |
| 123 | if ve, ok := err.(*errors.Validation); ok { |
| 124 | return ve.ValidateName("rack") |
| 125 | } |
| 126 | return err |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | return nil |
| 131 | } |
| 132 | |
| 133 | func (m *RackReservation) validateTenant(formats strfmt.Registry) error { |
| 134 | |
| 135 | if err := validate.Required("tenant", "body", m.Tenant); err != nil { |
| 136 | return err |
| 137 | } |
| 138 | |
| 139 | if m.Tenant != nil { |
| 140 | |
| 141 | if err := m.Tenant.Validate(formats); err != nil { |
| 142 | if ve, ok := err.(*errors.Validation); ok { |
| 143 | return ve.ValidateName("tenant") |
| 144 | } |
| 145 | return err |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | return nil |
| 150 | } |
| 151 | |
| 152 | func (m *RackReservation) validateUnits(formats strfmt.Registry) error { |
| 153 | |
| 154 | if err := validate.Required("units", "body", m.Units); err != nil { |
| 155 | return err |
| 156 | } |
| 157 | |
| 158 | for i := 0; i < len(m.Units); i++ { |
| 159 | |
| 160 | if swag.IsZero(m.Units[i]) { // not required |
| 161 | continue |
| 162 | } |
| 163 | |
| 164 | if err := validate.MinimumInt("units"+"."+strconv.Itoa(i), "body", int64(*m.Units[i]), 0, false); err != nil { |
| 165 | return err |
| 166 | } |
| 167 | |
| 168 | if err := validate.MaximumInt("units"+"."+strconv.Itoa(i), "body", int64(*m.Units[i]), 32767, false); err != nil { |
| 169 | return err |
| 170 | } |
| 171 | |
| 172 | } |
| 173 | |
| 174 | return nil |
| 175 | } |
| 176 | |
| 177 | func (m *RackReservation) validateUser(formats strfmt.Registry) error { |
| 178 | |
| 179 | if err := validate.Required("user", "body", m.User); err != nil { |
| 180 | return err |
| 181 | } |
| 182 | |
| 183 | if m.User != nil { |
| 184 | |
| 185 | if err := m.User.Validate(formats); err != nil { |
| 186 | if ve, ok := err.(*errors.Validation); ok { |
| 187 | return ve.ValidateName("user") |
| 188 | } |
| 189 | return err |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | return nil |
| 194 | } |
| 195 | |
| 196 | // MarshalBinary interface implementation |
| 197 | func (m *RackReservation) MarshalBinary() ([]byte, error) { |
| 198 | if m == nil { |
| 199 | return nil, nil |
| 200 | } |
| 201 | return swag.WriteJSON(m) |
| 202 | } |
| 203 | |
| 204 | // UnmarshalBinary interface implementation |
| 205 | func (m *RackReservation) UnmarshalBinary(b []byte) error { |
| 206 | var res RackReservation |
| 207 | if err := swag.ReadJSON(b, &res); err != nil { |
| 208 | return err |
| 209 | } |
| 210 | *m = res |
| 211 | return nil |
| 212 | } |