Skip to content

Commit

Permalink
error thrown in case of missing reference has properties missingRef a…
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Sep 2, 2015
1 parent ed7c148 commit bec34c5
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 335 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Options can have properties `separator` (string used to separate errors, ", " by
- _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 http://json-schema.org/schema or http://json-schema.org/draft-04/schema or absent (draft-4 meta-schema will be used) or can be a reference to the schema previously added with `addMetaSchema` method. If the validation fails, the exception is thrown. Pass "log" in this option to log error instead of throwing exception. Pass `false` to skip schema validation.
- _inlineRefs_: by default the referenced schemas that don't have refs in them are inlined, regardless of their size - that substantially improves performance at the cost of the bigger size of compiled schema functions. Pass `false` to not inline referenced schemas (they will be compiled as separate functions). Pass integer number to limit the maximum number of keywords of the schema that will be inlined.
- _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.
- _missingRefs_: by default if the reference cannot be resolved during compilation the exception is thrown. The thrown error has properties `missingRef` (with hash fragment) and `missingSchema` (without it). Both properties are resolved relative to the current base id (usually schema id, unless it was substituted). 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.
Expand Down
7 changes: 6 additions & 1 deletion lib/dot/ref.jst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@
{{ console.log($message); }}
{{? $breakOnError }} if (true) { {{?}}
{{??}}
{{ throw new Error($message); }}
{{
var $error = new Error($message);
$error.missingRef = it.resolve.url(it.baseId, $schema);
$error.missingSchema = it.resolve.normalizeId(it.resolve.fullPath($error.missingRef));
throw $error;
}}
{{?}}
{{?? typeof $refVal == 'string' }}
{{# def.validateRef:$refVal }}
Expand Down
97 changes: 0 additions & 97 deletions lib/dotjs/ref.js

This file was deleted.

182 changes: 0 additions & 182 deletions lib/dotjs/validate.js

This file was deleted.

Loading

0 comments on commit bec34c5

Please sign in to comment.