What is the best way to pass an array of values into unknownFormats
This is more of a query than an issue.
The following command called from Powershell works fine and returns errors for unknown formats:
ajv validate -d data.json -s schema.json --unknown-formats ignore --verbose --errors text --all-errors
To ignore specific formats the following command also works fine (after trying many different variations to pass multiple values for the unknown-formats parameter):
ajv validate -d data.json -s schema.json --unknown-formats="int32" --unknown-formats="double" --verbose --errors text --all-errors
Is there a better way to pass in the additional formats in the unknown-formats parameter without repeating --unknown-formats?
Just checked minimist docs - doesn't seem like it supports another way of passing arrays...
I can suggest creating a JS file with ~~empty~~ always valid format definitions for the formats you want to ignore and pass it to -c option:
const unknownFormats = ["int32", "double"]
module.exports = (ajv) => {
for (const f of unknownFormats) ajv.addFormat(f, () => true)
return ajv
}
// or `/.*/` can be used as format that should be ignored
// ajv v7 also supports just `true` to achieve the same in a slightly more performant way
// - it does not generate any code for formats defined as `true`
Also, given that unknown-formats option is removed from ajv v7, this will be the only way to define ignored formats once ajv-cli catches up with v7.
It would be good to add it to the docs - PR is welcome.