diff --git a/src/event/schemas.ts b/src/event/schemas.ts index 27cfd11..9444a98 100644 --- a/src/event/schemas.ts +++ b/src/event/schemas.ts @@ -79,6 +79,7 @@ export const schemaV1 = { source: { format: "uri-reference", type: "string", + minLength: 1, }, }, type: "object", diff --git a/test/integration/cloud_event_test.ts b/test/integration/cloud_event_test.ts index 1c7ee42..6b624f0 100644 --- a/test/integration/cloud_event_test.ts +++ b/test/integration/cloud_event_test.ts @@ -209,4 +209,20 @@ describe("A 1.0 CloudEvent", () => { expect(obj.source).to.equal(source); expect(obj.specversion).to.equal(Version.V1); }); + + it("throws if the provded source is empty string", () => { + try { + new CloudEvent({ + id: "0815", + specversion: "1.0", + type: "my.event.type", + source: "", + }); + } catch (err) { + expect(err).to.be.instanceOf(TypeError); + expect(err.message).to.include("invalid payload"); + expect(err.errors[0].dataPath).to.equal(".source"); + expect(err.errors[0].keyword).to.equal("minLength"); + } + }); });