Skip to content

Commit a39e895

Browse files
committed
Merge branch 'develop'
2 parents 7bf109a + 124d0c8 commit a39e895

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ var config = {
120120
url : "https://myserver.com"
121121
};
122122

123+
/*
124+
* To use HTTP Binary:
125+
* Cloudevent.bindings["http-binary0.2"](config);
126+
*/
127+
123128
// The binding instance
124129
var binding = Cloudevent.bindings["http-structured0.1"](config);
125130

ext/spec_0_2.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
"time": {
3333
"$ref": "#/definitions/time"
3434
},
35+
"schemaurl": {
36+
"$ref": "#/definitions/schemaurl"
37+
},
3538
"type": {
3639
"$ref": "#/definitions/type"
3740
},
@@ -58,6 +61,10 @@
5861
"format": "date-time",
5962
"type": "string"
6063
},
64+
"schemaurl": {
65+
"type": "string",
66+
"format": "uri"
67+
},
6168
"type": {
6269
"type": "string",
6370
"minLength": 1

lib/specs/spec_0_2.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ const reserved = {
1616

1717
const schema = require("../../ext/spec_0_2.json");
1818

19-
// Default options
20-
const ajv = new Ajv();
19+
const ajv = new Ajv({
20+
extendRefs: true // validate all keywords in the schemas with $ref (the default behaviour in versions before 5.0.0)
21+
});
2122

2223
const validate = ajv.compile(schema);
2324

@@ -36,7 +37,7 @@ Spec02.prototype.check = function(){
3637
var valid = validate(this.payload);
3738

3839
if(!valid) {
39-
throw {message: "invalid payload"};
40+
throw {message: "invalid payload", errors: validate.errors};
4041
}
4142

4243
};

test/cloudevent_spec_0_2.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
4040
expect(cloudevent.format()).to.have.property("specversion");
4141
});
4242

43+
it("should throw an error when mandatory attribute is absent", () => {
44+
delete cloudevent.spec.payload.source;
45+
expect(cloudevent.format.bind(cloudevent))
46+
.to
47+
.throw("invalid payload");
48+
cloudevent.spec.payload.source = source;
49+
});
50+
4351
it("requires 'source'", () => {
4452
expect(cloudevent.format()).to.have.property("source");
4553
});
@@ -60,6 +68,14 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
6068
expect(cloudevent.format()).to.have.property("schemaurl");
6169
});
6270

71+
it("should throw an error when 'schemaurl' is not an URI", () => {
72+
cloudevent.spec.payload.schemaurl = "KKKKKK";
73+
expect(cloudevent.format.bind(cloudevent))
74+
.to
75+
.throw("invalid payload");
76+
cloudevent.spec.payload.schemaurl = schemaurl;
77+
});
78+
6379
it("contains 'contenttype'", () => {
6480
cloudevent.contenttype(contenttype);
6581
expect(cloudevent.format()).to.have.property("contenttype");

0 commit comments

Comments
 (0)