Skip to content

Commit c18f4ca

Browse files
committed
fix: ensure that event data can be an array or number
The schema incorrectly limits data values to only object and string. This is incorrect, since JSON can be an array or a single number as well. Fixes: cloudevents#280 Signed-off-by: Lance Ball <lball@redhat.com>
1 parent 4a371b3 commit c18f4ca

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/event/schemas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const schemaV1 = {
1010
type: "string",
1111
},
1212
data: {
13-
type: ["object", "string"],
13+
type: ["object", "string", "array", "number"],
1414
},
1515
data_base64: {
1616
type: "string",
@@ -89,7 +89,7 @@ export const schemaV03 = {
8989
type: "string",
9090
},
9191
data: {
92-
type: ["object", "string"],
92+
type: ["object", "string", "array", "number"],
9393
},
9494
event: {
9595
properties: {

test/integration/cloud_event_test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ describe("A 1.0 CloudEvent", () => {
101101
expect(ce.data).to.deep.equal({ lunch: "tacos" });
102102
});
103103

104+
it("can be constructed with data as an Array", () => {
105+
const ce = new CloudEvent({
106+
...fixture,
107+
data: [{ lunch: "tacos" }, { supper: "sushi" }],
108+
});
109+
expect(ce.data).to.deep.equal([{ lunch: "tacos" }, { supper: "sushi" }]);
110+
});
111+
112+
it("can be constructed with data as a number", () => {
113+
const ce = new CloudEvent({
114+
...fixture,
115+
data: 100,
116+
});
117+
expect(ce.data).to.equal(100);
118+
});
119+
104120
it("can be constructed with extensions", () => {
105121
const extensions = {
106122
extensionkey: "extension-value",

0 commit comments

Comments
 (0)