Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit b0a0013

Browse files
chore(deps): Update module github.com/santhosh-tekuri/jsonschema/v5 to v6 (#693)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Matt Johnson-Pint <mjp@hypermode.com>
1 parent f9ce52a commit b0a0013

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

lib/manifest/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ go 1.23.1
55
toolchain go1.23.4
66

77
require (
8-
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
8+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1
99
github.com/tidwall/gjson v1.18.0
1010
github.com/tidwall/jsonc v0.3.2
1111
)
1212

1313
require (
1414
github.com/tidwall/match v1.1.1 // indirect
1515
github.com/tidwall/pretty v1.2.1 // indirect
16+
golang.org/x/text v0.14.0 // indirect
1617
)

lib/manifest/go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
2-
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
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=
3+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw=
4+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
35
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
46
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
57
github.com/tidwall/jsonc v0.3.2 h1:ZTKrmejRlAJYdn0kcaFqRAKlxxFIC21pYq8vLa4p2Wc=
@@ -9,3 +11,5 @@ github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JT
911
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
1012
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
1113
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
14+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
15+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=

lib/manifest/manifest.go

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
package manifest
1111

1212
import (
13+
"bytes"
1314
_ "embed"
1415
"encoding/json"
1516
"fmt"
17+
"strings"
1618

17-
"github.com/santhosh-tekuri/jsonschema/v5"
19+
"github.com/santhosh-tekuri/jsonschema/v6"
1820
"github.com/tidwall/gjson"
1921
"github.com/tidwall/jsonc"
2022
)
@@ -28,6 +30,7 @@ const currentVersion = 3
2830

2931
//go:embed modus_schema.json
3032
var schemaContent string
33+
var schema *jsonschema.Schema
3134

3235
type Manifest struct {
3336
Version int `json:"-"`
@@ -54,34 +57,43 @@ func (m *Manifest) GetVariables() map[string][]string {
5457
return results
5558
}
5659

60+
func init() {
61+
doc, err := jsonschema.UnmarshalJSON(strings.NewReader(schemaContent))
62+
if err != nil {
63+
panic(fmt.Errorf("failed to parse manifest schema: %w", err))
64+
}
65+
66+
c := jsonschema.NewCompiler()
67+
if err := c.AddResource("modus.json", doc); err != nil {
68+
panic(fmt.Errorf("failed to add manifest schema: %w", err))
69+
}
70+
71+
if sch, err := c.Compile("modus.json"); err != nil {
72+
panic(fmt.Errorf("failed to compile manifest schema: %w", err))
73+
} else {
74+
schema = sch
75+
}
76+
}
77+
5778
func IsCurrentVersion(version int) bool {
5879
return version == currentVersion
5980
}
6081

6182
func ValidateManifest(content []byte) error {
62-
63-
sch, err := jsonschema.CompileString("modus.json", schemaContent)
83+
r := bytes.NewReader(jsonc.ToJSON(content))
84+
doc, err := jsonschema.UnmarshalJSON(r)
6485
if err != nil {
65-
return err
86+
return fmt.Errorf("failed to parse manifest: %w", err)
6687
}
6788

68-
content = jsonc.ToJSONInPlace(content)
69-
70-
var v interface{}
71-
if err := json.Unmarshal(content, &v); err != nil {
72-
return fmt.Errorf("failed to deserialize manifest: %w", err)
73-
}
74-
if err := sch.Validate(v); err != nil {
89+
if err := schema.Validate(doc); err != nil {
7590
return fmt.Errorf("failed to validate manifest: %w", err)
7691
}
7792

7893
return nil
7994
}
8095

8196
func ReadManifest(content []byte) (*Manifest, error) {
82-
83-
content = jsonc.ToJSONInPlace(content)
84-
8597
var manifest Manifest
8698
if err := parseManifestJson(content, &manifest); err != nil {
8799
return nil, fmt.Errorf("failed to parse manifest: %w", err)
@@ -96,7 +108,7 @@ func parseManifestJson(data []byte, manifest *Manifest) error {
96108
Connections map[string]json.RawMessage `json:"connections"`
97109
Collections map[string]CollectionInfo `json:"collections"`
98110
}
99-
if err := json.Unmarshal(data, &m); err != nil {
111+
if err := json.Unmarshal(jsonc.ToJSON(data), &m); err != nil {
100112
return fmt.Errorf("failed to parse manifest: %w", err)
101113
}
102114

0 commit comments

Comments
 (0)