@@ -32,6 +32,7 @@ import (
32
32
33
33
schema "github.com/xeipuuv/gojsonschema"
34
34
"tags.cncf.io/container-device-interface/internal/validation"
35
+ cdi "tags.cncf.io/container-device-interface/specs-go"
35
36
)
36
37
37
38
const (
@@ -48,6 +49,13 @@ type Schema struct {
48
49
schema * schema.Schema
49
50
}
50
51
52
+ func (s * Schema ) Validate (spec * cdi.Spec ) error {
53
+ if s == nil {
54
+ return nil
55
+ }
56
+ return s .ValidateType (spec )
57
+ }
58
+
51
59
// Error wraps a JSON validation result.
52
60
type Error struct {
53
61
Result * schema.Result
@@ -98,7 +106,7 @@ func ReadAndValidate(r io.Reader) ([]byte, error) {
98
106
99
107
// Validate validates the data read from an io.Reader against the active schema.
100
108
func Validate (r io.Reader ) error {
101
- return current .Validate (r )
109
+ return current .ValidateReader (r )
102
110
}
103
111
104
112
// ValidateData validates the given JSON document against the active schema.
@@ -165,8 +173,8 @@ func (s *Schema) ReadAndValidate(r io.Reader) ([]byte, error) {
165
173
return data , s .validate (loader )
166
174
}
167
175
168
- // Validate validates the data read from an io.Reader against the schema.
169
- func (s * Schema ) Validate (r io.Reader ) error {
176
+ // ValidateReader validates the data read from an io.Reader against the schema.
177
+ func (s * Schema ) ValidateReader (r io.Reader ) error {
170
178
_ , err := s .ReadAndValidate (r )
171
179
return err
172
180
}
0 commit comments