github.com/digitalocean/go-netbox@v0.0.2/netbox/models/nested_user.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 // Copyright 2020 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 18 package models 19 20 // This file was generated by the swagger tool. 21 // Editing this file might prove futile when you re-run the swagger generate command 22 23 import ( 24 "context" 25 26 "github.com/go-openapi/errors" 27 "github.com/go-openapi/strfmt" 28 "github.com/go-openapi/swag" 29 "github.com/go-openapi/validate" 30 ) 31 32 // NestedUser nested user 33 // 34 // swagger:model NestedUser 35 type NestedUser struct { 36 37 // Display 38 // Read Only: true 39 Display string `json:"display,omitempty"` 40 41 // ID 42 // Read Only: true 43 ID int64 `json:"id,omitempty"` 44 45 // Url 46 // Read Only: true 47 // Format: uri 48 URL strfmt.URI `json:"url,omitempty"` 49 50 // Username 51 // 52 // Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only. 53 // Required: true 54 // Max Length: 150 55 // Min Length: 1 56 // Pattern: ^[\w.@+-]+$ 57 Username *string `json:"username"` 58 } 59 60 // Validate validates this nested user 61 func (m *NestedUser) Validate(formats strfmt.Registry) error { 62 var res []error 63 64 if err := m.validateURL(formats); err != nil { 65 res = append(res, err) 66 } 67 68 if err := m.validateUsername(formats); err != nil { 69 res = append(res, err) 70 } 71 72 if len(res) > 0 { 73 return errors.CompositeValidationError(res...) 74 } 75 return nil 76 } 77 78 func (m *NestedUser) validateURL(formats strfmt.Registry) error { 79 if swag.IsZero(m.URL) { // not required 80 return nil 81 } 82 83 if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil { 84 return err 85 } 86 87 return nil 88 } 89 90 func (m *NestedUser) validateUsername(formats strfmt.Registry) error { 91 92 if err := validate.Required("username", "body", m.Username); err != nil { 93 return err 94 } 95 96 if err := validate.MinLength("username", "body", *m.Username, 1); err != nil { 97 return err 98 } 99 100 if err := validate.MaxLength("username", "body", *m.Username, 150); err != nil { 101 return err 102 } 103 104 if err := validate.Pattern("username", "body", *m.Username, `^[\w.@+-]+$`); err != nil { 105 return err 106 } 107 108 return nil 109 } 110 111 // ContextValidate validate this nested user based on the context it is used 112 func (m *NestedUser) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 113 var res []error 114 115 if err := m.contextValidateDisplay(ctx, formats); err != nil { 116 res = append(res, err) 117 } 118 119 if err := m.contextValidateID(ctx, formats); err != nil { 120 res = append(res, err) 121 } 122 123 if err := m.contextValidateURL(ctx, formats); err != nil { 124 res = append(res, err) 125 } 126 127 if len(res) > 0 { 128 return errors.CompositeValidationError(res...) 129 } 130 return nil 131 } 132 133 func (m *NestedUser) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error { 134 135 if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil { 136 return err 137 } 138 139 return nil 140 } 141 142 func (m *NestedUser) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 143 144 if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 145 return err 146 } 147 148 return nil 149 } 150 151 func (m *NestedUser) contextValidateURL(ctx context.Context, formats strfmt.Registry) error { 152 153 if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil { 154 return err 155 } 156 157 return nil 158 } 159 160 // MarshalBinary interface implementation 161 func (m *NestedUser) MarshalBinary() ([]byte, error) { 162 if m == nil { 163 return nil, nil 164 } 165 return swag.WriteJSON(m) 166 } 167 168 // UnmarshalBinary interface implementation 169 func (m *NestedUser) UnmarshalBinary(b []byte) error { 170 var res NestedUser 171 if err := swag.ReadJSON(b, &res); err != nil { 172 return err 173 } 174 *m = res 175 return nil 176 }