Skip to content
Snippets Groups Projects
Commit e22dc08b authored by Ken Brooks's avatar Ken Brooks
Browse files

more tweaks from PR review

parent bba7ce28
Branches
Tags
No related merge requests found
......@@ -82,25 +82,33 @@ func realMain(args []string) int {
// Compile target schema
sl := gojsonschema.NewSchemaLoader()
schemaUri := *schemaFlag
schemaPath, err := filepath.Abs(*schemaFlag)
if err != nil {
log.Fatalf("%s: unable to convert to absolute path: %s\n", *schemaFlag, err)
}
for _, ref := range refFlags {
for _, p := range glob(ref) {
if p == schemaUri {
absPath, absPathErr := filepath.Abs(p)
if absPathErr != nil {
log.Fatalf("%s: unable to convert to absolute path: %s\n", absPath, err)
}
if absPath == schemaPath {
continue
}
loader, err := jsonLoader(p)
loader, err := jsonLoader(absPath)
if err != nil {
log.Fatalf("%s: unable to load schema ref: %s\n", *schemaFlag, err)
}
addSchemaErr := sl.AddSchemas(loader)
if addSchemaErr != nil {
if err := sl.AddSchemas(loader); err != nil {
log.Fatalf("%s: invalid schema: %s\n", p, err)
}
}
}
schemaLoader, err := jsonLoader(schemaUri)
schemaLoader, err := jsonLoader(schemaPath)
if err != nil {
log.Fatalf("%s: unable to load schema: %s\n", *schemaFlag, err)
}
......@@ -125,14 +133,15 @@ func realMain(args []string) int {
loader, err := jsonLoader(path)
if err != nil {
msg := fmt.Sprintf("%s: unable to load doc: %s\n", *schemaFlag, err)
msg := fmt.Sprintf("%s: error: load doc %s\n", path, err)
fmt.Println(msg)
errors = append(errors, msg)
} else {
return
}
result, err := schema.Validate(loader)
switch {
case err != nil:
msg := fmt.Sprintf("%s: error: %s", path, err)
msg := fmt.Sprintf("%s: error: validate: %s", path, err)
fmt.Println(msg)
errors = append(errors, msg)
......@@ -148,7 +157,6 @@ func realMain(args []string) int {
case !*quietFlag:
fmt.Printf("%s: pass\n", path)
}
}
}(p)
}
wg.Wait()
......@@ -190,7 +198,7 @@ func jsonLoader(path string) (gojsonschema.JSONLoader, error) {
}
func printUsage() {
fmt.Fprintf(os.Stderr, `Usage: %s -s schema.json|schema.yml [options] document.json|document.yml ...
fmt.Fprintf(os.Stderr, `Usage: %s -s schema.(json|yml) [options] document.(json|yml) ...
yajsv validates JSON and YAML document(s) against a schema. One of three statuses are
reported per document:
......
......@@ -84,7 +84,7 @@ func ExampleMain_error_jsonschema_jsondoc() {
log.Fatalf("exit: got %d, want 2", exit)
}
// Output:
// testdata\data-error.json: error: invalid character 'o' in literal null (expecting 'u')
// testdata\data-error.json: error: validate: invalid character 'o' in literal null (expecting 'u')
}
func ExampleMain_error_ymlschema_ymldoc() {
......@@ -93,7 +93,7 @@ func ExampleMain_error_ymlschema_ymldoc() {
log.Fatalf("exit: got %d, want 2", exit)
}
// Output:
// testdata\schema.yml: unable to load doc: yaml: found unexpected end of stream
// testdata\data-error.yml: error: load doc yaml: found unexpected end of stream
}
func ExampleMain_glob_jsonschema_jsondoc() {
......@@ -102,7 +102,7 @@ func ExampleMain_glob_jsonschema_jsondoc() {
log.Fatalf("exit: got %d, want 3", exit)
}
// Unordered output:
// testdata\data-error.json: error: invalid character 'o' in literal null (expecting 'u')
// testdata\data-error.json: error: validate: invalid character 'o' in literal null (expecting 'u')
// testdata\data-fail.json: fail: (root): foo is required
}
......@@ -112,7 +112,7 @@ func ExampleMain_glob_ymlschema_ymldoc() {
log.Fatalf("exit: got %d, want 3", exit)
}
// Unordered output:
// testdata\schema.yml: unable to load doc: yaml: found unexpected end of stream
// testdata\data-error.yml: error: load doc yaml: found unexpected end of stream
//
// testdata\data-fail.yml: fail: (root): foo is required
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment