missingRefs option - "ignore", "fail" or throw error during compilation (default)

master
Evgeny Poberezkin 2015-06-17 22:23:49 +01:00
parent 2ae8c89708
commit 5b2ba08813
3 changed files with 16 additions and 10 deletions

View File

@ -153,7 +153,8 @@ Returns the text with all errors in a String. Options can have these properties:
- _format_: formats validation mode ('fast' by default). Pass 'full' for more correct and slow validation or `false` not to validate formats at all. E.g., 25:00:00 and 2015/14/33 will be invalid time and date in 'full' mode but it will be valid in 'fast' mode.
- _formats_: an object with custom formats. Keys and values will be passed to `addFormat` method.
- _meta_: add [meta-schema](http://json-schema.org/documentation.html) so it can be used by other schemas (true by default).
- _validateSchema: validate added/compiled schemas against meta-schema (true by default). `$schema` property in the schema can either be absent (draft-4 meta-schema will be used) or can be a reference to any previously added schema. If the validation fails, the exception is thrown. Pass "log" in this option to log error instead of throwing exception.
- _validateSchema_: validate added/compiled schemas against meta-schema (true by default). `$schema` property in the schema can either be absent (draft-4 meta-schema will be used) or can be a reference to any previously added schema. If the validation fails, the exception is thrown. Pass "log" in this option to log error instead of throwing exception.
- _missingRefs_: by default if the reference cannot be resolved during compilation the exception is thrown. Pass 'ignore' to log error during compilation and pass validation. Pass 'fail' to log error and successfully compile schema but fail validation if this rule is checked.
- _uniqueItems_: validate `uniqueItems` keyword (true by default).
- _unicode_: calculate correct length of strings with unicode pairs (true by default). Pass `false` to use `.length` of strings that is faster, but gives "incorrect" lengths of strings with unicode pairs - each unicode pair is counted as two characters.
- _beautify_: format the generated function with [js-beautify](https://github.com/beautify-web/js-beautify) (the validating function is generated without line-breaks). `npm install js-beautify` to use this option. `true` or js-beautify options can be passed.

View File

@ -26,18 +26,23 @@
} {{? $breakOnError }} else { {{?}}
{{?}}
{{??}}
{{ var $v = 'v' + $lvl; }}
var {{=$v}} = root.refVal[0];
{{# def.validateRef:$v }}
{{# def.validateRef:'root.refVal[0]' }}
{{?}}
{{??}}
{{ var $refVal = it.resolveRef(it.baseId, $schema, it.rootId); }}
{{? $refVal === undefined }}
{{# def.error:'$ref' }}
{{? $breakOnError }} if (false) { {{?}}
{{ var $message = 'can\'t resolve reference ' + $schema; }}
{{? it.opts.missingRefs == 'fail' }}
{{ console.log($message); }}
{{# def.error:'$ref' }}
{{? $breakOnError }} if (false) { {{?}}
{{?? it.opts.missingRefs == 'ignore' }}
{{ console.log($message); }}
{{? $breakOnError }} if (true) { {{?}}
{{??}}
{{ throw new Error($message); }}
{{?}}
{{??}}
{{ var $v = 'v' + $lvl; }}
var {{=$v}} = {{=$refVal}};
{{# def.validateRef:$v }}
{{# def.validateRef:$refVal }}
{{?}}
{{?}}

View File

@ -1,6 +1,6 @@
{
"name": "ajv",
"version": "0.5.3",
"version": "0.5.4",
"description": "Another JSON schema Validator",
"main": "lib/ajv.js",
"scripts": {