@@ -32,6 +32,7 @@ import (
3232
3333 schema "github.com/xeipuuv/gojsonschema"
3434 "tags.cncf.io/container-device-interface/internal/validation"
35+ cdi "tags.cncf.io/container-device-interface/specs-go"
3536)
3637
3738const (
@@ -48,6 +49,13 @@ type Schema struct {
4849 schema * schema.Schema
4950}
5051
52+ func (s * Schema ) Validate (spec * cdi.Spec ) error {
53+ if s == nil {
54+ return nil
55+ }
56+ return s .ValidateType (spec )
57+ }
58+
5159// Error wraps a JSON validation result.
5260type Error struct {
5361 Result * schema.Result
@@ -98,7 +106,7 @@ func ReadAndValidate(r io.Reader) ([]byte, error) {
98106
99107// Validate validates the data read from an io.Reader against the active schema.
100108func Validate (r io.Reader ) error {
101- return current .Validate (r )
109+ return current .ValidateReader (r )
102110}
103111
104112// ValidateData validates the given JSON document against the active schema.
@@ -165,8 +173,8 @@ func (s *Schema) ReadAndValidate(r io.Reader) ([]byte, error) {
165173 return data , s .validate (loader )
166174}
167175
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 {
170178 _ , err := s .ReadAndValidate (r )
171179 return err
172180}
0 commit comments