Skip to content

Commit 49262cf

Browse files
committed
Update to github.com/santhosh-tekuri/jsonschema/v6
This requires adding a $schema field to defs-descriptor.json, otherwise the "format": "uri" restriction was is ignored. Signed-off-by: Miloslav Trmač <[email protected]>
1 parent 57afb95 commit 49262cf

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

schema/defs-descriptor.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"description": "Definitions particular to OpenContainer Descriptor Specification",
3+
"$schema": "http://json-schema.org/draft-04/schema#",
34
"definitions": {
45
"mediaType": {
56
"id": "https://opencontainers.org/schema/image/descriptor/mediaType",

schema/go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ module github.com/opencontainers/image-spec/schema
33
// The minimum Go release is only incremented when required by a feature.
44
// At least 3 Go releases will be supported by the spec.
55
// For example, updating this version to 1.19 first requires Go 1.21 to be released.
6-
go 1.18
6+
go 1.21
77

88
require (
99
github.com/opencontainers/go-digest v1.0.0
1010
github.com/opencontainers/image-spec v1.1.1
1111
github.com/russross/blackfriday v1.6.0
12-
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
12+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1
1313
)
14+
15+
require golang.org/x/text v0.14.0 // indirect

schema/go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
2+
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
13
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
24
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
35
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
46
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
5-
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
6-
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
7+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw=
8+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
9+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
10+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=

schema/validator.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
digest "github.com/opencontainers/go-digest"
2626
v1 "github.com/opencontainers/image-spec/specs-go/v1"
27-
"github.com/santhosh-tekuri/jsonschema/v5"
27+
"github.com/santhosh-tekuri/jsonschema/v6"
2828
)
2929

3030
// 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 {
8383
if file.IsDir() {
8484
continue
8585
}
86-
specBuf, err := specFS.ReadFile(file.Name())
86+
specFile, err := specFS.Open(file.Name())
8787
if err != nil {
8888
return fmt.Errorf("could not read spec file %s: %w", file.Name(), err)
8989
}
90-
err = c.AddResource(file.Name(), bytes.NewReader(specBuf))
90+
defer specFile.Close()
91+
spec, err := jsonschema.UnmarshalJSON(specFile)
92+
if err != nil {
93+
return fmt.Errorf("could not decode spec file %s: %w", file.Name(), err)
94+
}
95+
err = c.AddResource(file.Name(), spec)
9196
if err != nil {
9297
return fmt.Errorf("failed to add spec file %s: %w", file.Name(), err)
9398
}
@@ -96,7 +101,7 @@ func (v Validator) validateSchema(src io.Reader) error {
96101
return fmt.Errorf("spec file has no aliases: %s", file.Name())
97102
}
98103
for _, specURL := range specURLs[file.Name()] {
99-
err = c.AddResource(specURL, bytes.NewReader(specBuf))
104+
err = c.AddResource(specURL, spec)
100105
if err != nil {
101106
return fmt.Errorf("failed to add spec file %s as url %s: %w", file.Name(), specURL, err)
102107
}
@@ -110,8 +115,7 @@ func (v Validator) validateSchema(src io.Reader) error {
110115
}
111116

112117
// read in the user input and validate
113-
var input interface{}
114-
err = json.NewDecoder(src).Decode(&input)
118+
input, err := jsonschema.UnmarshalJSON(src)
115119
if err != nil {
116120
return fmt.Errorf("unable to parse json to validate: %w", err)
117121
}

0 commit comments

Comments
 (0)