justify icon indicating copy to clipboard operation
justify copied to clipboard

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

Open ghost opened this issue 5 years ago • 4 comments

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'.

ghost avatar Sep 29 '19 01:09 ghost

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

leadpony avatar Sep 29 '19 14:09 leadpony

Thanks @leadpony 🙂

ghost avatar Sep 29 '19 16:09 ghost

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.

leadpony avatar Oct 05 '19 10:10 leadpony

@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.

ghost avatar Oct 05 '19 15:10 ghost