Skip to content

Commit

Permalink
refactor: remove uri format change during schema validation, closes #906
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Dec 16, 2018
1 parent 9380a10 commit 223058b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
10 changes: 1 addition & 9 deletions lib/ajv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion spec/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down

0 comments on commit 223058b

Please sign in to comment.