molnarg / js-schema

Simple and intuitive schema validator
http://molnarg.github.com/js-schema/
MIT License
388 stars 45 forks source link

Strict mode #46

Open Cyri-L opened 8 years ago

Cyri-L commented 8 years ago

How do we force strict mode on the schemas ? Meaning that unspecified keys are unauthorized ? Thanks a lot

molnarg commented 8 years ago

Did you try "*": null ?

Cyri-L notifications@github.com ezt írta (időpont: 2016. márc. 1., K 23:51):

How do we force strict mode on the schemas ? Meaning that unspecified keys are unauthorized ? Thanks a lot

— Reply to this email directly or view it on GitHub https://github.com/molnarg/js-schema/issues/46.

Cyri-L commented 8 years ago

The problem is that by putting "*":null you allow properties to have value == void 0, which is not equal to !hasOwnProperty. Where should I add this feature into your structure?

molnarg commented 8 years ago

Null should mean that there's no such property. Undwfined means it has one, but the value is null or undefined. If it doesn't work that way, it's probably a bug.

Cyri-L notifications@github.com ezt írta (időpont: 2016. márc. 2., Sze 9:26):

The problem is that by putting "*" you allow properties to have value == void 0, which is not equal to !hasOwnProperty. Where should I add this feature into your structure?

— Reply to this email directly or view it on GitHub https://github.com/molnarg/js-schema/issues/46#issuecomment-191125685.

Cyri-L commented 8 years ago

Thank you, unfortunately it doesn't fully work. "*":null prevents from adding unspecified keys but the errors related to those additional keys are not reported into .errors() function

harmvandendorpel commented 8 years ago

I think this should be achieved by using the property additionalProperties. Don't know where to set its value though.

"This provides a default property definition for all properties that are not explicitly defined in an object type definition. The value must be a schema. If false is provided, no additional properties are allowed, and the schema can not be extended. The default value is an empty schema which allows any value for additional properties. "