Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudEvent data in Array format throws a ValidationError #280

Closed
lance opened this issue Jul 28, 2020 · 2 comments · Fixed by #281
Closed

CloudEvent data in Array format throws a ValidationError #280

lance opened this issue Jul 28, 2020 · 2 comments · Fixed by #281
Assignees
Labels
module/lib Related to the main source code spec/0.3 Support for spec v0.3 spec/1.0 Issues related to the CE specification type/bug Something isn't working

Comments

@lance
Copy link
Member

lance commented Jul 28, 2020

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

@lance lance added type/bug Something isn't working spec/0.3 Support for spec v0.3 spec/1.0 Issues related to the CE specification module/lib Related to the main source code labels Jul 28, 2020
@lance lance self-assigned this Jul 28, 2020
@lance
Copy link
Member Author

lance commented Jul 28, 2020

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.

lance added a commit to lance/sdk-javascript that referenced this issue Jul 28, 2020
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>
@lance
Copy link
Member Author

lance commented Jul 28, 2020

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

lance added a commit that referenced this issue Jul 29, 2020
…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: #280

Signed-off-by: Lance Ball <lball@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/lib Related to the main source code spec/0.3 Support for spec v0.3 spec/1.0 Issues related to the CE specification type/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant