Skip to content

Commit

Permalink
docs: update documentation match new Validator sig
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Jan 20, 2018
1 parent 00b42a8 commit 6bed992
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ func main() {
"lastName" : "Michael"
}`)

if err := rs.ValidateBytes(valid); err != nil {
if errors := rs.ValidateBytes(valid); len(errors) > 0 {
panic(err)
}

var invalidPerson = []byte(`{
"firstName" : "Prince"
}`)
err := rs.ValidateBytes(invalidPerson)
fmt.Println(err.Error())
if errors := rs.ValidateBytes(invalidPerson); len(errors) > 0 {
fmt.Println(errs[0].Error())
}

var invalidFriend = []byte(`{
"firstName" : "Jay",
Expand All @@ -92,8 +93,9 @@ func main() {
"firstName" : "Nas"
}]
}`)
err = rs.ValidateBytes(invalidFriend)
fmt.Println(err)
if errors := rs.ValidateBytes(invalidFriend); len(errors) > 0 {
fmt.Println(errors[0].Error())
}
}
```

Expand Down Expand Up @@ -124,10 +126,12 @@ func newIsFoo() jsonschema.Validator {
}

// Validate implements jsonschema.Validator
func (f IsFoo) Validate(data interface{}) error {
func (f IsFoo) Validate(data interface{}) []jsonschema.ValError {
if str, ok := data.(string); ok {
if str != "foo" {
return fmt.Errorf("'%s' is not foo. It should be foo. plz make '%s' == foo. plz", str, str)
return []jsonschema.ValError{
{Message: fmt.Sprintf("'%s' is not foo. It should be foo. plz make '%s' == foo. plz", str, str)},
}
}
}
return nil
Expand All @@ -148,10 +152,10 @@ func main() {
}

// validate some JSON
err := rs.ValidateBytes([]byte(`"bar"`))
errors := rs.ValidateBytes([]byte(`"bar"`))

// print le error
fmt.Println(err.Error())
fmt.Println(errs[0].Error())

// Output: 'bar' is not foo. It should be foo. plz make 'bar' == foo. plz
}
Expand Down

0 comments on commit 6bed992

Please sign in to comment.