From 8dae385eaa759141f320941897e026f536b0b6cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Mon, 21 Jan 2019 08:39:04 -0200 Subject: [PATCH 1/5] Document http binary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 63dbb72..afc99c3 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,11 @@ var config = { url : "https://myserver.com" }; +/* + * To use HTTP Binary: + * Cloudevent.bindings["http-binary0.2"](config); + */ + // The binding instance var binding = Cloudevent.bindings["http-structured0.1"](config); From d02f21c9231dedf82d17641431f7b4dd2c584f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Mon, 21 Jan 2019 09:11:26 -0200 Subject: [PATCH 2/5] Add schemaurl def MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- ext/spec_0_2.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ext/spec_0_2.json b/ext/spec_0_2.json index aa892a1..2848dc0 100644 --- a/ext/spec_0_2.json +++ b/ext/spec_0_2.json @@ -32,6 +32,9 @@ "time": { "$ref": "#/definitions/time" }, + "schemaurl": { + "$ref": "#/definitions/schemaurl" + }, "type": { "$ref": "#/definitions/type" }, @@ -58,6 +61,10 @@ "format": "date-time", "type": "string" }, + "schemaurl": { + "type": "string", + "format": "uri" + }, "type": { "type": "string", "minLength": 1 From 4cde6753ace522d365cc710f7c129445f59ddbb2 Mon Sep 17 00:00:00 2001 From: Kirusi Date: Wed, 17 Apr 2019 10:31:17 -0400 Subject: [PATCH 3/5] Changed JSON schema validator's options to remove warning: "$ref: keywords ignored in schema at path "#" " Signed-off-by: Kirusi Msafiri --- lib/specs/spec_0_2.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/specs/spec_0_2.js b/lib/specs/spec_0_2.js index 958dd6f..05b893b 100644 --- a/lib/specs/spec_0_2.js +++ b/lib/specs/spec_0_2.js @@ -16,8 +16,9 @@ const reserved = { const schema = require("../../ext/spec_0_2.json"); -// Default options -const ajv = new Ajv(); +const ajv = new Ajv({ + extendRefs: true // validate all keywords in the schemas with $ref (the default behaviour in versions before 5.0.0) +}); const validate = ajv.compile(schema); From 30796b21477cfa1556ffe2532b33ba382221dd50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Fri, 24 May 2019 09:16:49 -0300 Subject: [PATCH 4/5] Improve error message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- lib/specs/spec_0_2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/specs/spec_0_2.js b/lib/specs/spec_0_2.js index 958dd6f..d84561e 100644 --- a/lib/specs/spec_0_2.js +++ b/lib/specs/spec_0_2.js @@ -36,7 +36,7 @@ Spec02.prototype.check = function(){ var valid = validate(this.payload); if(!valid) { - throw {message: "invalid payload"}; + throw {message: "invalid payload", errors: validate.errors}; } }; From 3dd2993e5a78216777f0fae6b26bc9774403a632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Fri, 24 May 2019 09:17:28 -0300 Subject: [PATCH 5/5] More test cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- test/cloudevent_spec_0_2.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/test/cloudevent_spec_0_2.js b/test/cloudevent_spec_0_2.js index 6c7102c..733a00e 100644 --- a/test/cloudevent_spec_0_2.js +++ b/test/cloudevent_spec_0_2.js @@ -9,7 +9,7 @@ const contenttype = "application/json"; const data = {}; const extensions = {}; -var cloudevent = +var cloudevent = new Cloudevent(Cloudevent.specs["0.2"]) .type(type) .source(source); @@ -27,6 +27,14 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => { expect(cloudevent.format()).to.have.property("specversion"); }); + it("should throw an error when mandatory attribute is absent", () => { + delete cloudevent.spec.payload.source; + expect(cloudevent.format.bind(cloudevent)) + .to + .throw("invalid payload"); + cloudevent.spec.payload.source = source; + }); + it("requires 'source'", () => { expect(cloudevent.format()).to.have.property("source"); }); @@ -47,6 +55,14 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => { expect(cloudevent.format()).to.have.property("schemaurl"); }); + it("should throw an error when 'schemaurl' is not an URI", () => { + cloudevent.spec.payload.schemaurl = "KKKKKK"; + expect(cloudevent.format.bind(cloudevent)) + .to + .throw("invalid payload"); + cloudevent.spec.payload.schemaurl = schemaurl; + }); + it("contains 'contenttype'", () => { cloudevent.contenttype(contenttype); expect(cloudevent.format()).to.have.property("contenttype"); @@ -68,8 +84,8 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => { }); it("should throw an error when employ reserved name as extension", () => { - - var cevt = + + var cevt = new Cloudevent(Cloudevent.specs["0.2"]) .type(type) .source(source);