Skip to content

Commit

Permalink
allowed unknown formats
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Jul 18, 2020
1 parent c34840c commit bf63684
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -330,7 +330,7 @@ There are two modes of format validation: `fast` and `full`. This mode affects f

You can add additional formats and replace any of the formats above using [addFormat](#api-addformat) method.

The option `unknownFormats` allows changing the default behaviour when an unknown format is encountered. In this case Ajv can either fail schema compilation (default) or ignore it (default in versions before 5.0.0). You also can allowlist specific format(s) to be ignored. See [Options](#options) for details.
The option `unknownFormats` allows changing the default behaviour when an unknown format is encountered. In this case Ajv can either fail schema compilation (default) or ignore it (default in versions before 5.0.0). You also can allow specific format(s) that will be ignored. See [Options](#options) for details.

You can find regular expressions used for format validation and the sources that were used in [formats.js](https://github.com/ajv-validator/ajv/blob/master/lib/compile/formats.js).

Expand Down
16 changes: 11 additions & 5 deletions spec/extras/$data/format.json
Expand Up @@ -3,7 +3,11 @@
"description": "one property has format set in another property",
"schema": {
"properties": {
"str": { "format": { "$data": "1/strFormat" } },
"str": {
"format": {
"$data": "1/strFormat"
}
},
"strFormat": {}
}
},
Expand Down Expand Up @@ -49,15 +53,15 @@
"valid": false
},
{
"description": "allowlisted unknown format is valid",
"description": "allowed unknown format is valid",
"data": {
"str": "any value",
"strFormat": "allowedUnknown"
},
"valid": true
},
{
"description": "not allowlisted unknown format is invalid",
"description": "unknown format is invalid",
"data": {
"str": "any value",
"strFormat": "completelyUnknown"
Expand Down Expand Up @@ -85,7 +89,9 @@
"description": "property name is the format for the property value",
"schema": {
"additionalProperties": {
"format": { "$data": "0#" }
"format": {
"$data": "0#"
}
}
},
"tests": [
Expand Down Expand Up @@ -115,4 +121,4 @@
}
]
}
]
]
4 changes: 2 additions & 2 deletions spec/options/unknownFormats.spec.js
Expand Up @@ -70,7 +70,7 @@ describe('unknownFormats option', function() {
});

describe('= [String]', function() {
it('should pass schema compilation and be valid if alloylisted unknown format is used', function() {
it('should pass schema compilation and be valid if allowed unknown format is used', function() {
test(new Ajv({unknownFormats: ['allowed']}));

function test(ajv) {
Expand All @@ -83,7 +83,7 @@ describe('unknownFormats option', function() {
}
});

it('should be valid if alloylisted unknown format is used via $data', function() {
it('should be valid if allowed unknown format is used via $data', function() {
test(new Ajv({$data: true, unknownFormats: ['allowed']}));

function test(ajv) {
Expand Down
2 changes: 1 addition & 1 deletion spec/tests/rules/format.json
@@ -1,6 +1,6 @@
[
{
"description": "alloylisted unknown format is valid",
"description": "allowed unknown format is valid",
"schema": {
"format": "allowedUnknown"
},
Expand Down

0 comments on commit bf63684

Please sign in to comment.