Skip to content

Commit 0e9ff5a

Browse files
committed
dev: bump santhosh-tekuri/jsonschema/v5 to v6
1 parent 6b000ab commit 0e9ff5a

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ require (
9090
github.com/ryancurrah/gomodguard v1.3.5
9191
github.com/ryanrolds/sqlclosecheck v0.5.1
9292
github.com/sanposhiho/wastedassign/v2 v2.0.7
93-
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
93+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1
9494
github.com/sashamelentyev/interfacebloat v1.1.0
9595
github.com/sashamelentyev/usestdlibvars v1.27.0
9696
github.com/securego/gosec/v2 v2.21.4

go.sum

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/commands/config_verify.go

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package commands
22

33
import (
4+
"encoding/json"
45
"errors"
56
"fmt"
67
"net/http"
@@ -11,8 +12,7 @@ import (
1112

1213
hcversion "github.com/hashicorp/go-version"
1314
"github.com/pelletier/go-toml/v2"
14-
"github.com/santhosh-tekuri/jsonschema/v5"
15-
"github.com/santhosh-tekuri/jsonschema/v5/httploader"
15+
"github.com/santhosh-tekuri/jsonschema/v6"
1616
"github.com/spf13/cobra"
1717
"github.com/spf13/pflag"
1818
"gopkg.in/yaml.v3"
@@ -45,7 +45,7 @@ func (c *configCommand) executeVerify(cmd *cobra.Command, _ []string) error {
4545

4646
detail := v.DetailedOutput()
4747

48-
printValidationDetail(cmd, &detail)
48+
printValidationDetail(cmd, detail)
4949

5050
return errors.New("the configuration contains invalid elements")
5151
}
@@ -100,10 +100,13 @@ func createSchemaURL(flags *pflag.FlagSet, buildInfo BuildInfo) (string, error)
100100
}
101101

102102
func validateConfiguration(schemaPath, targetFile string) error {
103-
httploader.Client = &http.Client{Timeout: 2 * time.Second}
104-
105103
compiler := jsonschema.NewCompiler()
106-
compiler.Draft = jsonschema.Draft7
104+
loader := jsonschema.SchemeURLLoader{
105+
"file": jsonschema.FileLoader{},
106+
"https": newHTTPURLLoader(),
107+
}
108+
compiler.UseLoader(loader)
109+
compiler.DefaultDraft(jsonschema.Draft7)
107110

108111
schema, err := compiler.Compile(schemaPath)
109112
if err != nil {
@@ -133,10 +136,11 @@ func validateConfiguration(schemaPath, targetFile string) error {
133136
return schema.Validate(m)
134137
}
135138

136-
func printValidationDetail(cmd *cobra.Command, detail *jsonschema.Detailed) {
137-
if detail.Error != "" {
139+
func printValidationDetail(cmd *cobra.Command, detail *jsonschema.OutputUnit) {
140+
if detail.Error != nil {
141+
b, _ := json.Marshal(detail.Error)
138142
cmd.PrintErrf("jsonschema: %q does not validate with %q: %s\n",
139-
strings.ReplaceAll(strings.TrimPrefix(detail.InstanceLocation, "/"), "/", "."), detail.KeywordLocation, detail.Error)
143+
strings.ReplaceAll(strings.TrimPrefix(detail.InstanceLocation, "/"), "/", "."), detail.KeywordLocation, b)
140144
}
141145

142146
for _, d := range detail.Errors {
@@ -177,3 +181,26 @@ func decodeTomlFile(filename string) (any, error) {
177181

178182
return m, nil
179183
}
184+
185+
type httpURLLoader http.Client
186+
187+
func newHTTPURLLoader() *httpURLLoader {
188+
httpLoader := httpURLLoader(http.Client{
189+
Timeout: 2 * time.Second,
190+
})
191+
return &httpLoader
192+
}
193+
194+
func (l *httpURLLoader) Load(url string) (any, error) {
195+
client := (*http.Client)(l)
196+
resp, err := client.Get(url)
197+
if err != nil {
198+
return nil, err
199+
}
200+
defer resp.Body.Close()
201+
if resp.StatusCode != http.StatusOK {
202+
return nil, fmt.Errorf("%s returned status code %d", url, resp.StatusCode)
203+
}
204+
205+
return jsonschema.UnmarshalJSON(resp.Body)
206+
}

test/configuration_file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12-
"github.com/santhosh-tekuri/jsonschema/v5"
12+
"github.com/santhosh-tekuri/jsonschema/v6"
1313
"github.com/stretchr/testify/require"
1414
"gopkg.in/yaml.v3"
1515
)

0 commit comments

Comments
 (0)