Ajv: is making additionalProperties default false possible?

Created on 23 Nov 2017  路  1Comment  路  Source: ajv-validator/ajv

I always use ajv with removeAdditional='all', it works almost all the time for me.
but I cannot handle the case there is some object in object is free style, and it's content should not removed.

and I don't want to write additionalProperties=false in every schema. so if additionalProperties is default false, that will work.

can it be ?

suggestion wontfix

Most helpful comment

@taojoe making additionalProperties default to false would deviate from JSON schema specification and I don't won't to create options that facilitate it. So writing additionalProperties: false is the correct approach as it makes it explicit to all people who will read your code... The alternative is to traverse your schema programmatically (with json-schema-traverse) and assign additionalProperties: false to all subschemas that don't have additionalProperties: true.

>All comments

@taojoe making additionalProperties default to false would deviate from JSON schema specification and I don't won't to create options that facilitate it. So writing additionalProperties: false is the correct approach as it makes it explicit to all people who will read your code... The alternative is to traverse your schema programmatically (with json-schema-traverse) and assign additionalProperties: false to all subschemas that don't have additionalProperties: true.

Was this page helpful?
0 / 5 - 0 ratings