json-schema-validator icon indicating copy to clipboard operation
json-schema-validator copied to clipboard

Unknown fields are not validated.

Open vicky16898 opened this issue 2 years ago • 4 comments

The JSON Schema Validator appears to not raise errors when the payload includes fields that are not explicitly defined in the Swagger schema. This behavior prompts the question of whether the validator takes into account the "additionalProperties" flag specified in the Swagger definition to govern this aspect of validation.

vicky16898 avatar Sep 20 '23 08:09 vicky16898

Well I guess it does, but not for sub-schemas, as it is restricted to the scope of the individual sub schemas. https://json-schema.org/understanding-json-schema/reference/object.html#additional-properties

There was a feature in NetworkNt that subschemas are also validated when using unevalutatedProperties, but this is now restricted as of https://github.com/networknt/json-schema-validator/issues/826

So unevaluatedProperties also does not affect sub-schemas anymore, as the specification says so (although I cannot find the reference to this rule in the specs right now ;) ) This is also bugging me.

So for validating nested properties now you have to add the additionalProperties=false or unevaluatedProperties=false to each of the sub-schemas, which is redundant, but sadly how it works.

I hope I did address your issue. If you could give an example and explain what you expect, I could confirm this.

manuelwaltschek avatar Sep 20 '23 11:09 manuelwaltschek

@vicky16898 @manuelwaltschek I wonder if you want to test the latest version.

stevehu avatar Feb 28 '24 22:02 stevehu

@stevehu has anything changed regarding this? I haven't been up to date as I'm not working with the schema validation anymore.

manuelwaltschek avatar Mar 04 '24 23:03 manuelwaltschek

@justin-tay has refactored the library to resolve tons of issues and I think your issue is resolved already in the 1.3.3 version. Please verify when you have a chance. Thanks.

stevehu avatar Mar 05 '24 04:03 stevehu