leadpony / justify

Justify is a JSON validator based on JSON Schema Specification and Jakarta JSON Processing API (JSON-P).
Apache License 2.0
96 stars 18 forks source link

using "additionalProperties": false in the schema return `null` keyword if additional property passed in. #32

Open ghost opened 5 years ago

ghost commented 5 years ago

Hi, currently if we set "additionalProperties": false, and if the input contains additional fields, then the problem.keyword field is returns a null a value. For every other type of invalid format error, we get back proper keywords which help us categorize the type of problem (ex: 'maxLength', 'minLength', 'required'). It would be helpful it the keyword shows some value like 'additionalField'.

leadpony commented 5 years ago

Hi @adityamandhare Thank you for reporting the problem. I have successfully reproduced the problem. I will try to fix it. Sorry for your inconvenience.

ghost commented 5 years ago

Thanks @leadpony 🙂

leadpony commented 5 years ago

Hello @adityamandhare I labeled this issue as a bug, but I changed my mind after further consideration. additionalProperties is one of applicator keywords that apply subschemas but assert nothing on JSON instances by themselves. "additionalProperties": false means "apply the boolean schema false to any additional property found". As you know, the boolean schema false evaluates anything as invalid and the schema has no keywords. In the reported situation, calling Problem#getSchema() actually returns JsonSchema.FALSE which has no keywords. Therefore it is a correct behavior that Problem#getKeyword() returns null.

ghost commented 5 years ago

@leadpony thanks for working on this. Although this may not be a bug, having a keyword like additionalField or unexpectedField, or invalidField can always be helpful in case of additional properties are passed in when "additionalProperties": false.