fix: ensure that event data can be an array, number, boolean or null (#281)
The schema incorrectly limits data values to only object and string. This is incorrect, since JSON can be an array, boolean, a single number or null as well. This commit modifies the schema to allow for array, boolean and null, and adds tests. Fixes: https://github.com/cloudevents/sdk-javascript/issues/280 Signed-off-by: Lance Ball <lball@redhat.com>
This commit is contained in:
parent
c76dda6d10
commit
b99f728190
|
@ -10,7 +10,7 @@ export const schemaV1 = {
|
|||
type: "string",
|
||||
},
|
||||
data: {
|
||||
type: ["object", "string"],
|
||||
type: ["object", "string", "array", "number", "boolean", "null"],
|
||||
},
|
||||
data_base64: {
|
||||
type: "string",
|
||||
|
@ -89,7 +89,7 @@ export const schemaV03 = {
|
|||
type: "string",
|
||||
},
|
||||
data: {
|
||||
type: ["object", "string"],
|
||||
type: ["object", "string", "array", "number", "boolean", "null"],
|
||||
},
|
||||
event: {
|
||||
properties: {
|
||||
|
|
|
@ -101,6 +101,38 @@ 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 null data", () => {
|
||||
const ce = new CloudEvent({
|
||||
...fixture,
|
||||
data: null,
|
||||
});
|
||||
expect(ce.data).to.equal(null);
|
||||
});
|
||||
|
||||
it("can be constructed with data as a boolean", () => {
|
||||
const ce = new CloudEvent({
|
||||
...fixture,
|
||||
data: true,
|
||||
});
|
||||
expect(ce.data).to.be.true;
|
||||
});
|
||||
|
||||
it("can be constructed with extensions", () => {
|
||||
const extensions = {
|
||||
extensionkey: "extension-value",
|
||||
|
|
Loading…
Reference in New Issue