blob: dfc3fe8a061faf2d0a6731230887df72423f9d72 [file] [log] [blame]
Serge Bazanskicc25bdf2018-10-25 14:02:58 +02001// 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
17package 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
22import (
23 strfmt "github.com/go-openapi/strfmt"
24
25 "github.com/go-openapi/errors"
26 "github.com/go-openapi/swag"
27 "github.com/go-openapi/validate"
28)
29
30// Role role
31// swagger:model Role
32type Role struct {
33
34 // ID
35 // Read Only: true
36 ID int64 `json:"id,omitempty"`
37
38 // Name
39 // Required: true
40 // Max Length: 50
41 Name *string `json:"name"`
42
43 // Slug
44 // Required: true
45 // Max Length: 50
46 // Pattern: ^[-a-zA-Z0-9_]+$
47 Slug *string `json:"slug"`
48
49 // Weight
50 // Maximum: 32767
51 // Minimum: 0
52 Weight *int64 `json:"weight,omitempty"`
53}
54
55// Validate validates this role
56func (m *Role) Validate(formats strfmt.Registry) error {
57 var res []error
58
59 if err := m.validateName(formats); err != nil {
60 // prop
61 res = append(res, err)
62 }
63
64 if err := m.validateSlug(formats); err != nil {
65 // prop
66 res = append(res, err)
67 }
68
69 if err := m.validateWeight(formats); err != nil {
70 // prop
71 res = append(res, err)
72 }
73
74 if len(res) > 0 {
75 return errors.CompositeValidationError(res...)
76 }
77 return nil
78}
79
80func (m *Role) validateName(formats strfmt.Registry) error {
81
82 if err := validate.Required("name", "body", m.Name); err != nil {
83 return err
84 }
85
86 if err := validate.MaxLength("name", "body", string(*m.Name), 50); err != nil {
87 return err
88 }
89
90 return nil
91}
92
93func (m *Role) validateSlug(formats strfmt.Registry) error {
94
95 if err := validate.Required("slug", "body", m.Slug); err != nil {
96 return err
97 }
98
99 if err := validate.MaxLength("slug", "body", string(*m.Slug), 50); err != nil {
100 return err
101 }
102
103 if err := validate.Pattern("slug", "body", string(*m.Slug), `^[-a-zA-Z0-9_]+$`); err != nil {
104 return err
105 }
106
107 return nil
108}
109
110func (m *Role) validateWeight(formats strfmt.Registry) error {
111
112 if swag.IsZero(m.Weight) { // not required
113 return nil
114 }
115
116 if err := validate.MinimumInt("weight", "body", int64(*m.Weight), 0, false); err != nil {
117 return err
118 }
119
120 if err := validate.MaximumInt("weight", "body", int64(*m.Weight), 32767, false); err != nil {
121 return err
122 }
123
124 return nil
125}
126
127// MarshalBinary interface implementation
128func (m *Role) MarshalBinary() ([]byte, error) {
129 if m == nil {
130 return nil, nil
131 }
132 return swag.WriteJSON(m)
133}
134
135// UnmarshalBinary interface implementation
136func (m *Role) UnmarshalBinary(b []byte) error {
137 var res Role
138 if err := swag.ReadJSON(b, &res); err != nil {
139 return err
140 }
141 *m = res
142 return nil
143}