Skip to content

Commit

Permalink
fix(error): show error message for minLength (#73)
Browse files Browse the repository at this point in the history
Suppose, Schema contains one of the properties contains `minLength` like ```
{
    "type": "object",
    "properties": {
        "id": {
            "type": "string",
            "maxLength": 8,
            "minLength": 8
        }
    }
}
```
and attempted to validate JSON like 
```{
"id":"test"
}```
Currently, Validation raises message like `max length of 8 characters exceeded: test` and it is invalid error message
  • Loading branch information
Venkata bhaskar authored Jul 23, 2020
1 parent e7af1ef commit 0995c6b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion keywords_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (m MinLength) ValidateKeyword(ctx context.Context, currentState *Validation
schemaDebug("[MinLength] Validating")
if str, ok := data.(string); ok {
if utf8.RuneCountInString(str) < int(m) {
currentState.AddError(data, fmt.Sprintf("max length of %d characters exceeded: %s", m, str))
currentState.AddError(data, fmt.Sprintf("min length of %d characters required: %s", m, str))
}
}
}
Expand Down

0 comments on commit 0995c6b

Please sign in to comment.