eclipsesource/play-json-schema-validator

pattern for regexp is not included anymore?

Closed this issue · 3 comments

Hi,

I have upgraded from 0.8.4 to 0.8.7. Thank you for the improvements included.

I observed change in the messages:
0.8.4:
"asdfasdf* does not match pattern ^[A-Za-z0-9]+$"
0.8.7:
"Invalid pattern 'asdfasdf*'."

0.8.4 - It is clear why user's value does not match the pattern, but only if the user is a geek.
0.8.7 - It is not clear why user's value is a pattern and why it is invalid

Suggestion: allow to add human readable error message along side pattern specification in the json schema. Something like:
"myprop": {
"type": "string",
"pattern": "^[A-Za-z0-9]+$",
"patternMessage": "myprop can contain only letters and numbers"
}

In this case, the validator could place error message, like the following:
"Invalid string value 'asdfasdf*'. myprop can contain only letters and numbers"

If something like this is possible, it would be great. Otherwise, I would prefer to have 0.8.4 message style over 0.8.7

Thanks

OK. I have found some appropriate solution. I will expose "description" value of the property alongside with error messages from the validator. Description will capture human readable constraints. However, it becomes a bit different to all other messaging flows, as other messages (like numbers out of a range) are passes as is. Unfortunately we can not allow "Invalid pattern 'asdfasdf*'." message to escape because it is confusing for end user.

Thanks for pointing this out. This due an invalid/duplicate entry in messages.txt (duplicate str.pattern key). I'll fix this in the upcoming days.

Fixed with 0.8.8