...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package models
20
21
22
23
24 import (
25 "bytes"
26 "context"
27 "encoding/json"
28
29 "github.com/go-openapi/errors"
30 "github.com/go-openapi/strfmt"
31 "github.com/go-openapi/swag"
32 "github.com/go-openapi/validate"
33 )
34
35
36
37
38 type Intoto struct {
39
40
41
42
43 APIVersion *string `json:"apiVersion"`
44
45
46
47 Spec IntotoSchema `json:"spec"`
48 }
49
50
51 func (m *Intoto) Kind() string {
52 return "intoto"
53 }
54
55
56 func (m *Intoto) SetKind(val string) {
57 }
58
59
60 func (m *Intoto) UnmarshalJSON(raw []byte) error {
61 var data struct {
62
63
64
65
66 APIVersion *string `json:"apiVersion"`
67
68
69
70 Spec IntotoSchema `json:"spec"`
71 }
72 buf := bytes.NewBuffer(raw)
73 dec := json.NewDecoder(buf)
74 dec.UseNumber()
75
76 if err := dec.Decode(&data); err != nil {
77 return err
78 }
79
80 var base struct {
81
82
83 Kind string `json:"kind"`
84 }
85 buf = bytes.NewBuffer(raw)
86 dec = json.NewDecoder(buf)
87 dec.UseNumber()
88
89 if err := dec.Decode(&base); err != nil {
90 return err
91 }
92
93 var result Intoto
94
95 if base.Kind != result.Kind() {
96
97 return errors.New(422, "invalid kind value: %q", base.Kind)
98 }
99
100 result.APIVersion = data.APIVersion
101 result.Spec = data.Spec
102
103 *m = result
104
105 return nil
106 }
107
108
109 func (m Intoto) MarshalJSON() ([]byte, error) {
110 var b1, b2, b3 []byte
111 var err error
112 b1, err = json.Marshal(struct {
113
114
115
116
117 APIVersion *string `json:"apiVersion"`
118
119
120
121 Spec IntotoSchema `json:"spec"`
122 }{
123
124 APIVersion: m.APIVersion,
125
126 Spec: m.Spec,
127 })
128 if err != nil {
129 return nil, err
130 }
131 b2, err = json.Marshal(struct {
132 Kind string `json:"kind"`
133 }{
134
135 Kind: m.Kind(),
136 })
137 if err != nil {
138 return nil, err
139 }
140
141 return swag.ConcatJSON(b1, b2, b3), nil
142 }
143
144
145 func (m *Intoto) Validate(formats strfmt.Registry) error {
146 var res []error
147
148 if err := m.validateAPIVersion(formats); err != nil {
149 res = append(res, err)
150 }
151
152 if err := m.validateSpec(formats); err != nil {
153 res = append(res, err)
154 }
155
156 if len(res) > 0 {
157 return errors.CompositeValidationError(res...)
158 }
159 return nil
160 }
161
162 func (m *Intoto) validateAPIVersion(formats strfmt.Registry) error {
163
164 if err := validate.Required("apiVersion", "body", m.APIVersion); err != nil {
165 return err
166 }
167
168 if err := validate.Pattern("apiVersion", "body", *m.APIVersion, `^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`); err != nil {
169 return err
170 }
171
172 return nil
173 }
174
175 func (m *Intoto) validateSpec(formats strfmt.Registry) error {
176
177 if m.Spec == nil {
178 return errors.Required("spec", "body", nil)
179 }
180
181 return nil
182 }
183
184
185 func (m *Intoto) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
186 var res []error
187
188 if len(res) > 0 {
189 return errors.CompositeValidationError(res...)
190 }
191 return nil
192 }
193
194
195 func (m *Intoto) MarshalBinary() ([]byte, error) {
196 if m == nil {
197 return nil, nil
198 }
199 return swag.WriteJSON(m)
200 }
201
202
203 func (m *Intoto) UnmarshalBinary(b []byte) error {
204 var res Intoto
205 if err := swag.ReadJSON(b, &res); err != nil {
206 return err
207 }
208 *m = res
209 return nil
210 }
211
View as plain text