From 07f27426f3a69cd84dfb28da49c28b439dc8bd75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Tue, 29 Oct 2019 14:03:09 -0300 Subject: [PATCH] Method to check against the json schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- lib/specs/spec_1.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/specs/spec_1.js b/lib/specs/spec_1.js index b3e7ee6..f9dcb73 100644 --- a/lib/specs/spec_1.js +++ b/lib/specs/spec_1.js @@ -66,6 +66,17 @@ function Spec1(_caller) { }; } +/* + * Check the spec constraints + */ +Spec1.prototype.check = function(ce){ + var toCheck = (!ce ? this.payload : ce); + + if(!isValidAgainstSchema(toCheck)) { + throw {message: "invalid payload", errors: isValidAgainstSchema.errors}; + } +}; + Spec1.prototype.id = function(_id){ this.payload["id"] = _id; return this;