js-schema icon indicating copy to clipboard operation
js-schema copied to clipboard

Strict mode

Open Cyri-L opened this issue 9 years ago • 5 comments

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

Cyri-L avatar Mar 01 '16 22:03 Cyri-L

Did you try "*": null ?

Cyri-L [email protected] 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.

molnarg avatar Mar 02 '16 08:03 molnarg

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?

Cyri-L avatar Mar 02 '16 08:03 Cyri-L

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 [email protected] 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.

molnarg avatar Mar 02 '16 08:03 molnarg

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

Cyri-L avatar Mar 02 '16 09:03 Cyri-L

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

harmvandendorpel avatar Jul 11 '16 09:07 harmvandendorpel