Skip to content

Commit

Permalink
fix: addKeyword and schema without ID, closes #1001
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Apr 27, 2019
1 parent bc993de commit ab841b4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 34 deletions.
37 changes: 37 additions & 0 deletions lib/definition_schema.js
@@ -0,0 +1,37 @@
'use strict';

var metaSchema = require('./refs/json-schema-draft-07.json');

module.exports = {
$id: 'https://github.com/epoberezkin/ajv/blob/master/lib/definition_schema.js',
definitions: {
simpleTypes: metaSchema.definitions.simpleTypes
},
type: 'object',
dependencies: {
schema: ['validate'],
$data: ['validate'],
statements: ['inline'],
valid: {not: {required: ['macro']}}
},
properties: {
type: metaSchema.properties.type,
schema: {type: 'boolean'},
statements: {type: 'boolean'},
dependencies: {
type: 'array',
items: {type: 'string'}
},
metaSchema: {type: 'object'},
modifying: {type: 'boolean'},
valid: {type: 'boolean'},
$data: {type: 'boolean'},
async: {type: 'boolean'},
errors: {
anyOf: [
{type: 'boolean'},
{const: 'full'}
]
}
}
};
34 changes: 1 addition & 33 deletions lib/keyword.js
Expand Up @@ -2,7 +2,7 @@

var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i;
var customRuleCode = require('./dotjs/custom');
var metaSchema = require('./refs/json-schema-draft-07.json');
var definitionSchema = require('./definition_schema');

module.exports = {
add: addKeyword,
Expand All @@ -11,38 +11,6 @@ module.exports = {
validate: validateKeyword
};

var definitionSchema = {
definitions: {
simpleTypes: metaSchema.definitions.simpleTypes
},
type: 'object',
dependencies: {
schema: ['validate'],
$data: ['validate'],
statements: ['inline'],
valid: {not: {required: ['macro']}}
},
properties: {
type: metaSchema.properties.type,
schema: {type: 'boolean'},
statements: {type: 'boolean'},
dependencies: {
type: 'array',
items: {type: 'string'}
},
metaSchema: {type: 'object'},
modifying: {type: 'boolean'},
valid: {type: 'boolean'},
$data: {type: 'boolean'},
async: {type: 'boolean'},
errors: {
anyOf: [
{type: 'boolean'},
{const: 'full'}
]
}
}
};

/**
* Define custom keyword
Expand Down
2 changes: 1 addition & 1 deletion spec/JSON-Schema-Test-Suite
20 changes: 20 additions & 0 deletions spec/issues/1001_addKeyword_and_schema_without_id.spec.js
@@ -0,0 +1,20 @@
'use strict';

var Ajv = require('../ajv');
require('../chai').should();


describe('issue #1001: addKeyword breaks schema without ID', function() {
it('should allow using schemas without ID with addKeyword', function() {
var schema = {
definitions: {
foo: {}
}
};

var ajv = new Ajv();
ajv.addSchema(schema);
ajv.addKeyword('myKeyword', {});
ajv.getSchema('#/definitions/foo') .should.be.a('function');
});
});

0 comments on commit ab841b4

Please sign in to comment.