refactor: remove uri format change during schema validation, closes #906
parent
9380a105d6
commit
223058beb0
10
lib/ajv.js
10
lib/ajv.js
|
@ -55,8 +55,6 @@ function Ajv(opts) {
|
|||
this._refs = {};
|
||||
this._fragments = {};
|
||||
this._formats = formats(opts.format);
|
||||
var schemaUriFormat = this._schemaUriFormat = this._formats['uri-reference'];
|
||||
this._schemaUriFormatFunc = function (str) { return schemaUriFormat.test(str); };
|
||||
|
||||
this._cache = opts.cache || new Cache;
|
||||
this._loadingSchemas = {};
|
||||
|
@ -171,13 +169,7 @@ function validateSchema(schema, throwOrLogError) {
|
|||
this.errors = null;
|
||||
return true;
|
||||
}
|
||||
var currentUriFormat = this._formats.uri;
|
||||
this._formats.uri = typeof currentUriFormat == 'function'
|
||||
? this._schemaUriFormatFunc
|
||||
: this._schemaUriFormat;
|
||||
var valid;
|
||||
try { valid = this.validate($schema, schema); }
|
||||
finally { this._formats.uri = currentUriFormat; }
|
||||
var valid = this.validate($schema, schema);
|
||||
if (!valid && throwOrLogError) {
|
||||
var message = 'schema is invalid: ' + this.errorsText();
|
||||
if (this._opts.validateSchema == 'log') this.logger.error(message);
|
||||
|
|
|
@ -1194,7 +1194,7 @@ describe('Ajv Options', function () {
|
|||
describe('= "id"', function() {
|
||||
it('should use id and ignore $id', function() {
|
||||
var ajv = new Ajv({schemaId: 'id', meta: false});
|
||||
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
|
||||
ajv.addMetaSchema(require('../lib/refs/json-schema-draft-04.json'));
|
||||
ajv._opts.defaultMeta = 'http://json-schema.org/draft-04/schema#';
|
||||
|
||||
ajv.addSchema({ id: 'mySchema1', type: 'string' });
|
||||
|
|
Loading…
Reference in New Issue