Skip to content

Commit 937ea7b

Browse files
author
Mrunal Patel
authored
Merge pull request #490 from wking/json-schema-validate-http-schema
schema/validate: Allow schema identifiers to contain a URL scheme
2 parents b10c0b2 + 1db50f5 commit 937ea7b

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

schema/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ Then use it like:
3939
```bash
4040
./validate config-schema.json <yourpath>/config.json
4141
```
42+
43+
Or like:
44+
45+
```bash
46+
./validate https://raw.githubusercontent.com/opencontainers/runtime-spec/v1.0.0-rc1/schema/schema.json <yourpath>/config.json
47+
```

schema/validate.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io/ioutil"
66
"os"
77
"path/filepath"
8+
"strings"
89

910
"github.com/xeipuuv/gojsonschema"
1011
)
@@ -16,12 +17,17 @@ func main() {
1617
os.Exit(1)
1718
}
1819

19-
schemaPath, err := filepath.Abs(os.Args[1])
20-
if err != nil {
21-
fmt.Println(err)
22-
os.Exit(1)
20+
schemaPath := os.Args[1]
21+
if !strings.Contains(schemaPath, "://") {
22+
schemaPath, err := filepath.Abs(schemaPath)
23+
if err != nil {
24+
fmt.Println(err)
25+
os.Exit(1)
26+
}
27+
schemaPath = "file://" + schemaPath
2328
}
24-
schemaLoader := gojsonschema.NewReferenceLoader("file://" + schemaPath)
29+
schemaLoader := gojsonschema.NewReferenceLoader(schemaPath)
30+
2531
var documentLoader gojsonschema.JSONLoader
2632

2733
if nargs > 1 {

0 commit comments

Comments
 (0)