Description
Is your feature request related to a problem? Please describe.
Currently, when creating a CloudEvent
instance, one of the final things that happens in the constructor before freezing the object is this.validate()
is called. The validate()
function will throw an exception if the event is invalid. This effectively means that there is no way to create an event that's invalid. In most cases, this is probably for the best. But what happens if you have a system with a known bug that's emitting invalid events, and some JavaScript service using this module is receiving them. There's no way to actually do that without forking this repo.
Describe the solution you would like to see
- Optionally, don't call
this.validate()
in the constructor based on an addedboolean
parameter (strict: boolean = true
by default). - Change
Detector
interface from feat: introduce Message, Serializer, Deserializer and Binding interfaces #324 to use an optional parameter for loose validation. - Change the
Deserializer
interface which converts from aMessage
to aCloudEvent
to use an optional parameter for loose validation.
Additional context
This is all in the context of creating events manually, or deserializing an incoming Message
into a CloudEvent
. I haven't thought much about the serialization step. If a user manually creates an invalid event, and then serializes it to a Message
, should that throw an exception? I think maybe it should, but interested in other's opinions.