always stable-stringify schema, even if the string is passed
parent
c32264b258
commit
7dd2218fd4
18
lib/jv.js
18
lib/jv.js
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue