Skip to content

Commit

Permalink
fix: ensure that event data can be an array or number
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lance committed Jul 28, 2020
1 parent 4a371b3 commit c18f4ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/event/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const schemaV1 = {
type: "string",
},
data: {
type: ["object", "string"],
type: ["object", "string", "array", "number"],
},
data_base64: {
type: "string",
Expand Down Expand Up @@ -89,7 +89,7 @@ export const schemaV03 = {
type: "string",
},
data: {
type: ["object", "string"],
type: ["object", "string", "array", "number"],
},
event: {
properties: {
Expand Down
16 changes: 16 additions & 0 deletions test/integration/cloud_event_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ describe("A 1.0 CloudEvent", () => {
expect(ce.data).to.deep.equal({ lunch: "tacos" });
});

it("can be constructed with data as an Array", () => {
const ce = new CloudEvent({
...fixture,
data: [{ lunch: "tacos" }, { supper: "sushi" }],
});
expect(ce.data).to.deep.equal([{ lunch: "tacos" }, { supper: "sushi" }]);
});

it("can be constructed with data as a number", () => {
const ce = new CloudEvent({
...fixture,
data: 100,
});
expect(ce.data).to.equal(100);
});

it("can be constructed with extensions", () => {
const extensions = {
extensionkey: "extension-value",
Expand Down

0 comments on commit c18f4ca

Please sign in to comment.