From: =?utf-8?q?Miloslav_Trma=C4=8D?= Date: Fri, 14 Mar 2025 01:30:00 +0100 Subject: Update to github.com/santhosh-tekuri/jsonschema/v6 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit This requires adding a $schema field to defs-descriptor.json, otherwise the "format": "uri" restriction was is ignored. Signed-off-by: Miloslav Trmač --- go.mod | 8 ++++++-- go.sum | 8 ++++++-- schema/defs-descriptor.json | 1 + schema/validator.go | 16 ++++++++++------ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 9a45167..5c22cff 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,14 @@ module github.com/opencontainers/image-spec // The minimum Go release is only incremented when required by a feature. // At least 3 Go releases will be supported by the spec. // For example, updating this version to 1.19 first requires Go 1.21 to be released. -go 1.18 +go 1.21 + +toolchain go1.24.13 require ( github.com/opencontainers/go-digest v1.0.0 github.com/russross/blackfriday v1.6.0 - github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 + github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 ) + +require golang.org/x/text v0.14.0 // indirect diff --git a/go.sum b/go.sum index dcb5a93..c821b80 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,10 @@ +github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= +github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= -github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4= -github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY= +github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEVZGK7IN2kJkjTuQ= +github.com/santhosh-tekuri/jsonschema/v6 v6.0.2/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= diff --git a/schema/defs-descriptor.json b/schema/defs-descriptor.json index 056a799..6d15062 100644 --- a/schema/defs-descriptor.json +++ b/schema/defs-descriptor.json @@ -1,5 +1,6 @@ { "description": "Definitions particular to OpenContainer Descriptor Specification", + "$schema": "http://json-schema.org/draft-04/schema#", "definitions": { "mediaType": { "id": "https://opencontainers.org/schema/image/descriptor/mediaType", diff --git a/schema/validator.go b/schema/validator.go index 6c823b5..e323673 100644 --- a/schema/validator.go +++ b/schema/validator.go @@ -24,7 +24,7 @@ import ( digest "github.com/opencontainers/go-digest" v1 "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/santhosh-tekuri/jsonschema/v5" + "github.com/santhosh-tekuri/jsonschema/v6" ) // Validator wraps a media type string identifier and implements validation against a JSON schema. @@ -83,11 +83,16 @@ func (v Validator) validateSchema(src io.Reader) error { if file.IsDir() { continue } - specBuf, err := specFS.ReadFile(file.Name()) + specFile, err := specFS.Open(file.Name()) if err != nil { return fmt.Errorf("could not read spec file %s: %w", file.Name(), err) } - err = c.AddResource(file.Name(), bytes.NewReader(specBuf)) + defer specFile.Close() + spec, err := jsonschema.UnmarshalJSON(specFile) + if err != nil { + return fmt.Errorf("could not decode spec file %s: %w", file.Name(), err) + } + err = c.AddResource(file.Name(), spec) if err != nil { return fmt.Errorf("failed to add spec file %s: %w", file.Name(), err) } @@ -96,7 +101,7 @@ func (v Validator) validateSchema(src io.Reader) error { return fmt.Errorf("spec file has no aliases: %s", file.Name()) } for _, specURL := range specURLs[file.Name()] { - err = c.AddResource(specURL, bytes.NewReader(specBuf)) + err = c.AddResource(specURL, spec) if err != nil { return fmt.Errorf("failed to add spec file %s as url %s: %w", file.Name(), specURL, err) } @@ -110,8 +115,7 @@ func (v Validator) validateSchema(src io.Reader) error { } // read in the user input and validate - var input interface{} - err = json.NewDecoder(src).Decode(&input) + input, err := jsonschema.UnmarshalJSON(src) if err != nil { return fmt.Errorf("unable to parse json to validate: %w", err) }