Remove the responsability of spec checking
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
a2ae5b9231
commit
fb92f710ea
|
@ -1,9 +1,5 @@
|
||||||
var Spec02 = require("../../specs/spec_0_2.js");
|
function JSONParser() {
|
||||||
|
|
||||||
const spec02 = new Spec02();
|
|
||||||
|
|
||||||
function JSONParser(_spec) {
|
|
||||||
this.spec = (_spec) ? _spec : new Spec02();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,13 +41,10 @@ function validate_spec(payload, spec) {
|
||||||
|
|
||||||
JSONParser.prototype.parse = function(payload) {
|
JSONParser.prototype.parse = function(payload) {
|
||||||
|
|
||||||
// Level 0 of validation: is that string? is that JSON?
|
//is that string? is that JSON?
|
||||||
var valid0 = validate_and_parse_as_json(payload);
|
var valid = validate_and_parse_as_json(payload);
|
||||||
|
|
||||||
// Level 1 of validation: is that follow a spec?
|
return valid;
|
||||||
var valid1 = validate_spec(valid0, this.spec);
|
|
||||||
|
|
||||||
return valid1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = JSONParser;
|
module.exports = JSONParser;
|
||||||
|
|
Loading…
Reference in New Issue