Skip to content

CloudEvent data in Array format throws a ValidationError #280

Closed

Description

@lance

Describe the Bug

When creating or receiving a CloudEvent, if the data is in the form of an Array - which is valid JSON - we get a validation error.

Steps to Reproduce

  1. use new CloudEvent() to create an event with the data property as an array. For example:
const ce = new CloudEvent({ source: '/test', type: 'example', data: [ 1, 2, 3 ] });

That will produce:

   TypeError: invalid payload
      at Object.validateV1 (src/event/spec.ts:14:11)
      at CloudEvent.validate (src/event/cloudevent.ts:178:16)
      at new CloudEvent (src/event/cloudevent.ts:121:10)

Expected Behavior

No error thrown.

Additional context

The schema seems to have wrongly typed data here https://github.com/cloudevents/sdk-javascript/blob/master/src/event/schemas.ts#L12-L14 and here https://github.com/cloudevents/sdk-javascript/blob/master/src/event/schemas.ts#L91-L93

Activity

  1. added
    type/bugSomething isn't working
    spec/0.3Support for spec v0.3
    spec/1.0Issues related to the CE specification
    module/libRelated to the main source code
    on Jul 28, 2020
  2. self-assigned this
    on Jul 28, 2020
  3. lance commented on Jul 28, 2020

    @lance
    MemberAuthor

    Although the schema has not changed, in previous versions the event was (in most cases) validated on demand. With the new version, you are not allowed to create an invalid event. In this case, the event is not invalid, but the schema thinks it is.

  4. lance commented on Jul 28, 2020

    @lance
    MemberAuthor

    The fix for this also adds tests for boolean and null which are also valid JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

module/libRelated to the main source codespec/0.3Support for spec v0.3spec/1.0Issues related to the CE specificationtype/bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions