Using the Spec to check the format

Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
Fabio José 2019-06-21 10:58:05 -03:00
parent 62e5404c0f
commit fea87aaee2
1 changed files with 6 additions and 2 deletions

View File

@ -5,7 +5,8 @@ const Spec02 = require("../../specs/spec_0_2.js");
var JSONParser = require("../../formats/json/parser.js");
const jsonParserSpec02 = new JSONParser(new Spec02());
const spec02 = new Spec02();
const jsonParserSpec02 = new JSONParser();
const parser_by_mime = {};
parser_by_mime[Constants.MIME_JSON] = jsonParserSpec02;
@ -56,9 +57,12 @@ Receiver.prototype.parse = function(payload, headers) {
var contentType = sanity_headers[Constants.HEADER_CONTENT_TYPE];
var parser = parser_by_mime[contentType];
var cloudevent = parser.parse(payload);
// Must follow the spec
spec02.check(cloudevent);
return cloudevent;
}