@@ -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,15 @@ type Schema struct {
4849 schema * schema.Schema
4950}
5051
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+
5161// Error wraps a JSON validation result.
5262type Error struct {
5363 Result * schema.Result
@@ -96,9 +106,9 @@ func ReadAndValidate(r io.Reader) ([]byte, error) {
96106 return current .ReadAndValidate (r )
97107}
98108
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 )
102112}
103113
104114// ValidateData validates the given JSON document against the active schema.
@@ -165,8 +175,8 @@ func (s *Schema) ReadAndValidate(r io.Reader) ([]byte, error) {
165175 return data , s .validate (loader )
166176}
167177
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 {
170180 _ , err := s .ReadAndValidate (r )
171181 return err
172182}
0 commit comments