@@ -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,15 @@ type Schema struct {
48
49
schema * schema.Schema
49
50
}
50
51
52
+ // Validate applies a schema validation on the supplied CDI specification.
53
+ // If the Schema is nil, no validation is performed.
54
+ func (s * Schema ) Validate (spec * cdi.Spec ) error {
55
+ if s == nil {
56
+ return nil
57
+ }
58
+ return s .ValidateType (spec )
59
+ }
60
+
51
61
// Error wraps a JSON validation result.
52
62
type Error struct {
53
63
Result * schema.Result
@@ -96,9 +106,9 @@ func ReadAndValidate(r io.Reader) ([]byte, error) {
96
106
return current .ReadAndValidate (r )
97
107
}
98
108
99
- // Validate validates the data read from an io.Reader against the active schema.
100
- func Validate (r io.Reader ) error {
101
- return current .Validate (r )
109
+ // ValidateReader validates the data read from an io.Reader against the active schema.
110
+ func ValidateReader (r io.Reader ) error {
111
+ return current .ValidateReader (r )
102
112
}
103
113
104
114
// ValidateData validates the given JSON document against the active schema.
@@ -165,8 +175,8 @@ func (s *Schema) ReadAndValidate(r io.Reader) ([]byte, error) {
165
175
return data , s .validate (loader )
166
176
}
167
177
168
- // Validate validates the data read from an io.Reader against the schema.
169
- func (s * Schema ) Validate (r io.Reader ) error {
178
+ // ValidateReader validates the data read from an io.Reader against the schema.
179
+ func (s * Schema ) ValidateReader (r io.Reader ) error {
170
180
_ , err := s .ReadAndValidate (r )
171
181
return err
172
182
}
0 commit comments