You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem here is that JSON-schema validators like ajv infer if there is no additionalProperties: false then additional properties are allowed. This conflicts with the implementation of the ObjectValidator because if you want to allow additional properties you are required to chain .additional({ ... }) which should imply to the developer that when .additional({...}) is not used then to expect _additionalProperties: false_ in the json-schema output.
The text was updated successfully, but these errors were encountered:
In case anyone comes here looking for a solution, I patch the JSON-schema programmatically using this function:
/** * This function will recursively search for JSON-schema { type: 'object' } and add { additionalProperties: false } to them. * @param data */exportfunctionaddAdditionalPropertiesFalse(data: any){// If the current data is an object and not an array, proceedif(typeofdata==='object'&&!Array.isArray(data)){// Check if the object has the type property 'object'if(data.type==='object'){// Add the additionalProperties property set to falsedata.additionalProperties=false;}// Iterate over each property of the objectfor(letkeyindata){// If the property is an object or an array, recurse into itif(typeofdata[key]==='object'){addAdditionalPropertiesFalse(data[key]);}}}elseif(Array.isArray(data)){// Iterate over each item of the arrayfor(leti=0;i<data.length;i++){// If the item is an object or an array, recurse into itif(typeofdata[i]==='object'){addAdditionalPropertiesFalse(data[i]);}}}}
This validator:
Will produce this json-schema:
The problem here is that JSON-schema validators like ajv infer if there is no
additionalProperties: false
then additional properties are allowed. This conflicts with the implementation of theObjectValidator
because if you want to allow additional properties you are required to chain.additional({ ... })
which should imply to the developer that when.additional({...})
is not used then to expect_additionalProperties: false_
in the json-schema output.The text was updated successfully, but these errors were encountered: