ajv-cli icon indicating copy to clipboard operation
ajv-cli copied to clipboard

Is there a replacement for --unknown-formats?

Open gpakosz opened this issue 4 years ago • 3 comments

Hello,

The --unknown-formats option is gone. Is there a replacement?

My use case is using a schema for which a format has validation implemented in Python but I don't necessarily have an implementation that I can plug to ajv.

Thank you

gpakosz avatar Jun 10 '21 14:06 gpakosz

You can either disable format validation entirely or define it in a .js plugin and pass via -c option. so the file would look like:

module.export = (ajv) => ajv.addFormat("your_format", true)

epoberezkin avatar Jun 10 '21 14:06 epoberezkin

I see.

To be honest, neither is really appealing. Having to have .js plugins around to use ajv-cli doesn't sound quite right. To give more context, we have schemas that do this:

"definitions": {
  "something": {
    "format": "custom",
     "pattern": ...
  }
}

For which we write validation functions often in Python and we have "pattern" as a fallback

gpakosz avatar Jun 10 '21 15:06 gpakosz

@gpakosz If you can use the formats defined in https://github.com/ajv-validator/ajv-formats#formats, then you can easily add them with the following two steps:

  1. npm i -D ajv-formats
  2. Add -c ajv-formats to your CLI command for ajx.

Example:

ajv test -s my.schema.json -d my.json --spec=draft2019 -c ajv-formats --valid --all-errors --errors=text

If you can not use those formats then you should look at ajv-cli-custom.

dotnetCarpenter avatar Aug 14 '21 15:08 dotnetCarpenter