Skip to content

Commit acfd4df

Browse files
committed
review
1 parent 0e9ff5a commit acfd4df

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

pkg/commands/config_verify.go

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

33
import (
4+
"context"
45
"encoding/json"
56
"errors"
67
"fmt"
@@ -103,7 +104,7 @@ func validateConfiguration(schemaPath, targetFile string) error {
103104
compiler := jsonschema.NewCompiler()
104105
loader := jsonschema.SchemeURLLoader{
105106
"file": jsonschema.FileLoader{},
106-
"https": newHTTPURLLoader(),
107+
"https": newJSONSchemaHTTPLoader(),
107108
}
108109
compiler.UseLoader(loader)
109110
compiler.DefaultDraft(jsonschema.Draft7)
@@ -182,22 +183,29 @@ func decodeTomlFile(filename string) (any, error) {
182183
return m, nil
183184
}
184185

185-
type httpURLLoader http.Client
186+
type jsonschemaHTTPLoader struct {
187+
*http.Client
188+
}
186189

187-
func newHTTPURLLoader() *httpURLLoader {
188-
httpLoader := httpURLLoader(http.Client{
190+
func newJSONSchemaHTTPLoader() *jsonschemaHTTPLoader {
191+
return &jsonschemaHTTPLoader{Client: &http.Client{
189192
Timeout: 2 * time.Second,
190-
})
191-
return &httpLoader
193+
}}
192194
}
193195

194-
func (l *httpURLLoader) Load(url string) (any, error) {
195-
client := (*http.Client)(l)
196-
resp, err := client.Get(url)
196+
func (l jsonschemaHTTPLoader) Load(url string) (any, error) {
197+
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, http.NoBody)
197198
if err != nil {
198199
return nil, err
199200
}
201+
202+
resp, err := l.Do(req)
203+
if err != nil {
204+
return nil, err
205+
}
206+
200207
defer resp.Body.Close()
208+
201209
if resp.StatusCode != http.StatusOK {
202210
return nil, fmt.Errorf("%s returned status code %d", url, resp.StatusCode)
203211
}

test/configuration_file_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func Test_validateTestConfigurationFiles(t *testing.T) {
18-
err := validateTestConfigurationFiles("../jsonschema/golangci.next.jsonschema.json", ".")
18+
err := validateTestConfigurationFiles("../../jsonschema/golangci.next.jsonschema.json", ".")
1919
require.NoError(t, err)
2020
}
2121

@@ -59,7 +59,7 @@ func validateTestConfigurationFiles(schemaPath, targetDir string) error {
5959

6060
func loadSchema(schemaPath string) (*jsonschema.Schema, error) {
6161
compiler := jsonschema.NewCompiler()
62-
compiler.Draft = jsonschema.Draft7
62+
compiler.DefaultDraft(jsonschema.Draft7)
6363

6464
schemaFile, err := os.Open(schemaPath)
6565
if err != nil {
@@ -73,7 +73,7 @@ func loadSchema(schemaPath string) (*jsonschema.Schema, error) {
7373
return nil, fmt.Errorf("add schema resource: %w", err)
7474
}
7575

76-
schema, err := compiler.Compile(filepath.Base(schemaPath))
76+
schema, err := compiler.Compile(schemaPath)
7777
if err != nil {
7878
return nil, fmt.Errorf("compile schema: %w", err)
7979
}

0 commit comments

Comments
 (0)