...
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 Alert struct {
35
36
37
38 GeneratorURL strfmt.URI `json:"generatorURL,omitempty"`
39
40
41
42 Labels LabelSet `json:"labels"`
43 }
44
45
46 func (m *Alert) Validate(formats strfmt.Registry) error {
47 var res []error
48
49 if err := m.validateGeneratorURL(formats); err != nil {
50 res = append(res, err)
51 }
52
53 if err := m.validateLabels(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 *Alert) validateGeneratorURL(formats strfmt.Registry) error {
64 if swag.IsZero(m.GeneratorURL) {
65 return nil
66 }
67
68 if err := validate.FormatOf("generatorURL", "body", "uri", m.GeneratorURL.String(), formats); err != nil {
69 return err
70 }
71
72 return nil
73 }
74
75 func (m *Alert) validateLabels(formats strfmt.Registry) error {
76
77 if err := validate.Required("labels", "body", m.Labels); err != nil {
78 return err
79 }
80
81 if m.Labels != nil {
82 if err := m.Labels.Validate(formats); err != nil {
83 if ve, ok := err.(*errors.Validation); ok {
84 return ve.ValidateName("labels")
85 } else if ce, ok := err.(*errors.CompositeError); ok {
86 return ce.ValidateName("labels")
87 }
88 return err
89 }
90 }
91
92 return nil
93 }
94
95
96 func (m *Alert) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
97 var res []error
98
99 if err := m.contextValidateLabels(ctx, formats); err != nil {
100 res = append(res, err)
101 }
102
103 if len(res) > 0 {
104 return errors.CompositeValidationError(res...)
105 }
106 return nil
107 }
108
109 func (m *Alert) contextValidateLabels(ctx context.Context, formats strfmt.Registry) error {
110
111 if err := m.Labels.ContextValidate(ctx, formats); err != nil {
112 if ve, ok := err.(*errors.Validation); ok {
113 return ve.ValidateName("labels")
114 } else if ce, ok := err.(*errors.CompositeError); ok {
115 return ce.ValidateName("labels")
116 }
117 return err
118 }
119
120 return nil
121 }
122
123
124 func (m *Alert) MarshalBinary() ([]byte, error) {
125 if m == nil {
126 return nil, nil
127 }
128 return swag.WriteJSON(m)
129 }
130
131
132 func (m *Alert) UnmarshalBinary(b []byte) error {
133 var res Alert
134 if err := swag.ReadJSON(b, &res); err != nil {
135 return err
136 }
137 *m = res
138 return nil
139 }
140
View as plain text