...
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 "strconv"
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
33
34
35 type Matchers []*Matcher
36
37
38 func (m Matchers) Validate(formats strfmt.Registry) error {
39 var res []error
40
41 iMatchersSize := int64(len(m))
42
43 if err := validate.MinItems("", "body", iMatchersSize, 1); err != nil {
44 return err
45 }
46
47 for i := 0; i < len(m); i++ {
48 if swag.IsZero(m[i]) {
49 continue
50 }
51
52 if m[i] != nil {
53 if err := m[i].Validate(formats); err != nil {
54 if ve, ok := err.(*errors.Validation); ok {
55 return ve.ValidateName(strconv.Itoa(i))
56 } else if ce, ok := err.(*errors.CompositeError); ok {
57 return ce.ValidateName(strconv.Itoa(i))
58 }
59 return err
60 }
61 }
62
63 }
64
65 if len(res) > 0 {
66 return errors.CompositeValidationError(res...)
67 }
68 return nil
69 }
70
71
72 func (m Matchers) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
73 var res []error
74
75 for i := 0; i < len(m); i++ {
76
77 if m[i] != nil {
78 if err := m[i].ContextValidate(ctx, formats); err != nil {
79 if ve, ok := err.(*errors.Validation); ok {
80 return ve.ValidateName(strconv.Itoa(i))
81 } else if ce, ok := err.(*errors.CompositeError); ok {
82 return ce.ValidateName(strconv.Itoa(i))
83 }
84 return err
85 }
86 }
87
88 }
89
90 if len(res) > 0 {
91 return errors.CompositeValidationError(res...)
92 }
93 return nil
94 }
95
View as plain text