fix: addKeyword and schema without ID, closes #1001
parent
bc993decea
commit
ab841b462e
|
@ -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'}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i;
|
var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i;
|
||||||
var customRuleCode = require('./dotjs/custom');
|
var customRuleCode = require('./dotjs/custom');
|
||||||
var metaSchema = require('./refs/json-schema-draft-07.json');
|
var definitionSchema = require('./definition_schema');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
add: addKeyword,
|
add: addKeyword,
|
||||||
|
@ -11,38 +11,6 @@ module.exports = {
|
||||||
validate: validateKeyword
|
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
|
* Define custom keyword
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 15ba997f9b937150a0ab88244d1d0fbf58526c48
|
Subproject commit eadeacb04209a18fc81f1a1959e83eef72dcc97a
|
|
@ -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');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue