Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
yajsv - Yet Another Json Schema Validator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
SmartDataLab
public
CI-CD tools
yajsv - Yet Another Json Schema Validator
Commits
e22dc08b
Commit
e22dc08b
authored
5 years ago
by
Ken Brooks
Browse files
Options
Downloads
Patches
Plain Diff
more tweaks from PR review
parent
bba7ce28
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.go
+35
-27
35 additions, 27 deletions
main.go
main_windows_test.go
+4
-4
4 additions, 4 deletions
main_windows_test.go
with
39 additions
and
31 deletions
main.go
+
35
−
27
View file @
e22dc08b
...
...
@@ -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
addSchemaE
rr
!=
nil
{
if
err
:=
sl
.
AddSchemas
(
loader
);
e
rr
!=
nil
{
log
.
Fatalf
(
"%s: invalid schema: %s
\n
"
,
p
,
err
)
}
}
}
schemaLoader
,
err
:=
jsonLoader
(
schema
Uri
)
schemaLoader
,
err
:=
jsonLoader
(
schema
Path
)
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:
...
...
This diff is collapsed.
Click to expand it.
main_windows_test.go
+
4
−
4
View file @
e22dc08b
...
...
@@ -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
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment