Skip to content

Commit

Permalink
feat: include errors from properties/items
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Apr 15, 2017
1 parent 38214a8 commit f9fbcf5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -35,3 +35,8 @@ jspm_packages

# Optional REPL history
.node_repl_history

# Compiled templates
lib/dotjs/*.js

.DS_Store
12 changes: 10 additions & 2 deletions lib/dot/errorMessage.jst
Expand Up @@ -10,17 +10,25 @@
, $i = 'errorMessage_i' + $lvl
, $err = 'errorMessage_err' + $lvl
, $errors = 'errorMessage_errors' + $lvl
, $nextChar = 'errorMessage_nextChar' + $lvl
, $errSchemaPathString = it.util.toQuotedString(it.errSchemaPath);
}}
var {{=$dataPath}} = (dataPath || '') + {{= it.errorPath }};
{{? typeof $schema == 'string' }}
var {{=$i}} = 0;
var {{=$err}};
var {{=$err}}, {{=$nextChar}};
var {{=$errors}} = undefined;
while ({{=$i}}<errors) {
{{=$err}} = vErrors[{{=$i}}];
if ({{=$err}}.keyword != '{{=$keyword}}'
&& {{=$err}}.dataPath == {{=$dataPath}}
&& ({{=$err}}.dataPath == {{=$dataPath}} ||
({{=$err}}.dataPath.indexOf({{=$dataPath}}) == 0 &&
{{? it.opts.jsonPointers }}
{{=$err}}.dataPath[{{=$dataPath}}.length] == '/'
{{??}}
({{=$nextChar}} = {{=$err}}.dataPath[{{=$dataPath}}.length]) == '.'
|| {{=$nextChar}} == '['
{{?}}))
&& {{=$err}}.schemaPath.indexOf({{=$errSchemaPathString}}) == 0
&& {{=$err}}.schemaPath[{{=it.errSchemaPath.length}}] == '/') {
if ({{=$errors}}) {{=$errors}}.push({{=$err}});
Expand Down
3 changes: 3 additions & 0 deletions lib/dotjs/README.md
@@ -0,0 +1,3 @@
These files are compiled dot templates from dot folder.

Do NOT edit them directly, edit the templates and run `npm run build` from main ajv-keywords folder.
32 changes: 0 additions & 32 deletions lib/dotjs/errorMessage.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -8,7 +8,7 @@
"eslint": "eslint *.js spec",
"test-spec": "mocha spec/*.spec.js -R spec",
"test-cov": "nyc npm run test-spec",
"test": "npm run eslint && npm run test-cov"
"test": "npm run eslint && npm run build && npm run test-cov"
},
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions spec/string.spec.js
Expand Up @@ -14,7 +14,7 @@ describe('errorMessage value is a string', function() {
type: 'object',
required: ['foo'],
properties: {
foo: true/*{ type: 'integer' }*/
foo: { type: 'integer' }
},
additionalProperties: false,
errorMessage: 'should be an object with an integer property foo only'
Expand All @@ -25,8 +25,8 @@ describe('errorMessage value is a string', function() {
testInvalid({}, ['required']);
testInvalid({bar: 2}, ['required', 'additionalProperties']);
testInvalid({foo: 1, bar: 2}, ['additionalProperties']);
// testInvalid({foo: 'a'}, ['type']);
// testInvalid({foo: 'a', bar: 2}, ['type', 'additionalProperties']);
testInvalid({foo: 'a'}, ['type']);
testInvalid({foo: 'a', bar: 2}, ['type', 'additionalProperties']);
testInvalid(1, ['type']);

function testInvalid(data, expectedReplacedKeywords) {
Expand Down

0 comments on commit f9fbcf5

Please sign in to comment.