diff --git a/schema/README.md b/schema/README.md index 01a3e5ed8..6bdd00a29 100644 --- a/schema/README.md +++ b/schema/README.md @@ -37,3 +37,9 @@ Then use it like: ```bash ./validate schema.json /config.json ``` + +Or like: + +```bash +./validate https://raw.githubusercontent.com/opencontainers/runtime-spec/v1.0.0-rc1/schema/schema.json /config.json +``` diff --git a/schema/validate.go b/schema/validate.go index 34125cefd..48dd67e1a 100644 --- a/schema/validate.go +++ b/schema/validate.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "github.com/xeipuuv/gojsonschema" ) @@ -16,12 +17,17 @@ func main() { os.Exit(1) } - schemaPath, err := filepath.Abs(os.Args[1]) - if err != nil { - fmt.Println(err) - os.Exit(1) + schemaPath := os.Args[1] + if !strings.Contains(schemaPath, "://") { + schemaPath, err := filepath.Abs(schemaPath) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + schemaPath = "file://" + schemaPath } - schemaLoader := gojsonschema.NewReferenceLoader("file://" + schemaPath) + schemaLoader := gojsonschema.NewReferenceLoader(schemaPath) + var documentLoader gojsonschema.JSONLoader if nargs > 1 {