1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package models
18
19
20
21
22 import (
23 "context"
24
25 "github.com/go-openapi/errors"
26 "github.com/go-openapi/strfmt"
27 "github.com/go-openapi/swag"
28 "github.com/go-openapi/validate"
29 )
30
31
32
33
34 type PostableAlert struct {
35
36
37 Annotations LabelSet `json:"annotations,omitempty"`
38
39
40
41 EndsAt strfmt.DateTime `json:"endsAt,omitempty"`
42
43
44
45 StartsAt strfmt.DateTime `json:"startsAt,omitempty"`
46
47 Alert
48 }
49
50
51 func (m *PostableAlert) UnmarshalJSON(raw []byte) error {
52
53 var dataAO0 struct {
54 Annotations LabelSet `json:"annotations,omitempty"`
55
56 EndsAt strfmt.DateTime `json:"endsAt,omitempty"`
57
58 StartsAt strfmt.DateTime `json:"startsAt,omitempty"`
59 }
60 if err := swag.ReadJSON(raw, &dataAO0); err != nil {
61 return err
62 }
63
64 m.Annotations = dataAO0.Annotations
65
66 m.EndsAt = dataAO0.EndsAt
67
68 m.StartsAt = dataAO0.StartsAt
69
70
71 var aO1 Alert
72 if err := swag.ReadJSON(raw, &aO1); err != nil {
73 return err
74 }
75 m.Alert = aO1
76
77 return nil
78 }
79
80
81 func (m PostableAlert) MarshalJSON() ([]byte, error) {
82 _parts := make([][]byte, 0, 2)
83
84 var dataAO0 struct {
85 Annotations LabelSet `json:"annotations,omitempty"`
86
87 EndsAt strfmt.DateTime `json:"endsAt,omitempty"`
88
89 StartsAt strfmt.DateTime `json:"startsAt,omitempty"`
90 }
91
92 dataAO0.Annotations = m.Annotations
93
94 dataAO0.EndsAt = m.EndsAt
95
96 dataAO0.StartsAt = m.StartsAt
97
98 jsonDataAO0, errAO0 := swag.WriteJSON(dataAO0)
99 if errAO0 != nil {
100 return nil, errAO0
101 }
102 _parts = append(_parts, jsonDataAO0)
103
104 aO1, err := swag.WriteJSON(m.Alert)
105 if err != nil {
106 return nil, err
107 }
108 _parts = append(_parts, aO1)
109 return swag.ConcatJSON(_parts...), nil
110 }
111
112
113 func (m *PostableAlert) Validate(formats strfmt.Registry) error {
114 var res []error
115
116 if err := m.validateAnnotations(formats); err != nil {
117 res = append(res, err)
118 }
119
120 if err := m.validateEndsAt(formats); err != nil {
121 res = append(res, err)
122 }
123
124 if err := m.validateStartsAt(formats); err != nil {
125 res = append(res, err)
126 }
127
128
129 if err := m.Alert.Validate(formats); err != nil {
130 res = append(res, err)
131 }
132
133 if len(res) > 0 {
134 return errors.CompositeValidationError(res...)
135 }
136 return nil
137 }
138
139 func (m *PostableAlert) validateAnnotations(formats strfmt.Registry) error {
140
141 if swag.IsZero(m.Annotations) {
142 return nil
143 }
144
145 if m.Annotations != nil {
146 if err := m.Annotations.Validate(formats); err != nil {
147 if ve, ok := err.(*errors.Validation); ok {
148 return ve.ValidateName("annotations")
149 } else if ce, ok := err.(*errors.CompositeError); ok {
150 return ce.ValidateName("annotations")
151 }
152 return err
153 }
154 }
155
156 return nil
157 }
158
159 func (m *PostableAlert) validateEndsAt(formats strfmt.Registry) error {
160
161 if swag.IsZero(m.EndsAt) {
162 return nil
163 }
164
165 if err := validate.FormatOf("endsAt", "body", "date-time", m.EndsAt.String(), formats); err != nil {
166 return err
167 }
168
169 return nil
170 }
171
172 func (m *PostableAlert) validateStartsAt(formats strfmt.Registry) error {
173
174 if swag.IsZero(m.StartsAt) {
175 return nil
176 }
177
178 if err := validate.FormatOf("startsAt", "body", "date-time", m.StartsAt.String(), formats); err != nil {
179 return err
180 }
181
182 return nil
183 }
184
185
186 func (m *PostableAlert) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
187 var res []error
188
189 if err := m.contextValidateAnnotations(ctx, formats); err != nil {
190 res = append(res, err)
191 }
192
193
194 if err := m.Alert.ContextValidate(ctx, formats); err != nil {
195 res = append(res, err)
196 }
197
198 if len(res) > 0 {
199 return errors.CompositeValidationError(res...)
200 }
201 return nil
202 }
203
204 func (m *PostableAlert) contextValidateAnnotations(ctx context.Context, formats strfmt.Registry) error {
205
206 if err := m.Annotations.ContextValidate(ctx, formats); err != nil {
207 if ve, ok := err.(*errors.Validation); ok {
208 return ve.ValidateName("annotations")
209 } else if ce, ok := err.(*errors.CompositeError); ok {
210 return ce.ValidateName("annotations")
211 }
212 return err
213 }
214
215 return nil
216 }
217
218
219 func (m *PostableAlert) MarshalBinary() ([]byte, error) {
220 if m == nil {
221 return nil, nil
222 }
223 return swag.WriteJSON(m)
224 }
225
226
227 func (m *PostableAlert) UnmarshalBinary(b []byte) error {
228 var res PostableAlert
229 if err := swag.ReadJSON(b, &res); err != nil {
230 return err
231 }
232 *m = res
233 return nil
234 }
235
View as plain text