always stable-stringify schema, even if the string is passed

master
Evgeny Poberezkin 2015-05-20 02:02:47 +01:00
parent c32264b258
commit 7dd2218fd4
1 changed files with 6 additions and 12 deletions

View File

@ -1,7 +1,7 @@
'use strict';
var compileSchema = require('./compile')
, stringify = require('json-stable-stringify')
, stableStringify = require('json-stable-stringify')
module.exports = Jv;
@ -15,7 +15,7 @@ function Jv(opts) {
if (!(this instanceof Jv) return new Jv(opts);
this._opts = opts || {};
this._schemas = {};
this._bySource = {};
this._byJson = {};
}
Jv.prototype.addSchema = addSchema;
@ -54,16 +54,10 @@ function getSchema(name) {
function _addSchema(schema) {
var str;
if (typeof schema == 'string') {
str = schema;
schema = JSON.parse(schema);
} else if (typeof schema == 'object')
str = stringify(schema);
else
throw new Error('schema has invalid type');
return (this._bySource[str] = this._bySource[str] || compileSchema.call(this, schema));
if (typeof schema == 'string') schema = JSON.parse(schema);
if (typeof schema != 'object') throw new Error('schema has invalid type');
var str = stableStringify(schema);
return (this._byJson[str] = this._byJson[str] || compileSchema.call(this, schema));
}