-
Notifications
You must be signed in to change notification settings - Fork 69
Should throw if specversion attribute is missing #332
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
@satazor in this PR, there was discussion around loose validation on receipt of a That method returns a |
Oh - but I see the problem here. Since it's defaulting the |
The other required attribute that we supply a default for if it's not provided is |
This issue is stale because it has been open 30 days with no activity. |
I know this has been open for a while, but the idea is that we shouldn't be defaulting the specversion and id fields? This would be a good one to get into the 4.0 release. i can assign myself to take of it |
I think defaulting them on creation with sdk-javascript/src/message/http/index.ts Lines 58 to 60 in f6be285
Throwing here would also remove that |
@lance that sounds good. i'll take of it |
* When receiving an event, we should not default the specversion to 1.0 if no specverion field is detected. * If no specversion is detected or the specversion does not conform to a currently supported version, we will now throw a ValidationError This is a BREAKING_CHANGE fixes cloudevents#332, cloudevents#333 Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
* When receiving an event, we should not default the specversion to 1.0 if no specverion field is detected. * If no specversion is detected or the specversion does not conform to a currently supported version, we will now throw a ValidationError This is a BREAKING_CHANGE fixes cloudevents#332, cloudevents#333 Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
I think this should also be the same for the As of now,
sdk-javascript/src/message/http/index.ts Line 231 in 6be3b27
sdk-javascript/src/event/cloudevent.ts Line 61 in 6be3b27
PS: the same would also happen with the |
FYI, there is another effect that when calling sdk-javascript/src/message/http/index.ts Line 58 in 6be3b27
but the parsed event is actually getting the original value (e.g. sdk-javascript/src/message/http/index.ts Line 208 in 6be3b27
in binary mode this is prevented by this block: sdk-javascript/src/message/http/index.ts Line 129 in 6be3b27
no sure if therefore this block for structured should use the body attributes instead (I think sending ce-header even though structured mode is used is valid as long as the context attributes are present in the body)? sdk-javascript/src/message/http/index.ts Line 189 in 6be3b27
|
This issue is stale because it has been open 30 days with no activity. |
@lholmquist ping - were you still thinking you'd take this? If not, I'll pick it up. Running into this as an issue now with function runtime. |
This commit adds type definitions for the following: * `Invokable`: The user provided function * `Context`: The invocation context * `CloudEventResponse`: Convenience class for constructing events * `Logger`: The logging interface * `LogLevel`: Logging enumeration * `start`: A function to start the invoker * `InvokerOptions`: Options for `start` The definitions are statically tested with `tsd`. These type definitions are not actually used by the JS files. This does not convert the module to TypeScript; it just adds these type definitions to our exports. This will allow us to create TypeScript function templates without a full conversion of this code base to TypeScript. Ultimately, I think it's probably best to make the change. This change also bumps to `cloudevents@4.0.2` which does have a breaking change. See: cloudevents/sdk-javascript#332 As a result, we accept all versions of CloudEvents. Actually, I think this is probably a fine change in the long run. Loose validation upon receipt of an event allows functions to handle event sources that may be producing malformed events. I've commented out the test for now. If we decide it makes sense to leave this as-is instead of waiting for a fix from upstream, then we should remove the test and the existing logic for dealing with this, since it's no longer necessary. Finally, I've really simplified the `start` funtion interface. It now just takes a function and a bag of options. It doesn't deal with callbacks anymore. Promises are used to deal with async server startup. Signed-off-by: Lance Ball <lball@redhat.com>
This commit adds type definitions for the following: * `Invokable`: The user provided function * `Context`: The invocation context * `CloudEventResponse`: Convenience class for constructing events * `Logger`: The logging interface * `LogLevel`: Logging enumeration * `start`: A function to start the invoker * `InvokerOptions`: Options for `start` The definitions are statically tested with `tsd`. These type definitions are not actually used by the JS files. This does not convert the module to TypeScript; it just adds these type definitions to our exports. This will allow us to create TypeScript function templates without a full conversion of this code base to TypeScript. Ultimately, I think it's probably best to make the change. This change also bumps to `cloudevents@4.0.2` which does have a breaking change. See: cloudevents/sdk-javascript#332 As a result, we accept all versions of CloudEvents. Actually, I think this is probably a fine change in the long run. Loose validation upon receipt of an event allows functions to handle event sources that may be producing malformed events. I've commented out the test for now. If we decide it makes sense to leave this as-is instead of waiting for a fix from upstream, then we should remove the test and the existing logic for dealing with this, since it's no longer necessary. Finally, I've really simplified the `start` funtion interface. It now just takes a function and a bag of options. It doesn't deal with callbacks anymore. Promises are used to deal with async server startup. Signed-off-by: Lance Ball <lball@redhat.com>
@lance it isn't on my radar atm, so feel free to pick it up |
Even if the specversion is totally invalid, we should not change the value received in an incoming `Message`. Previously we defaulted to 1.0 if we did not recognize the version number. This commit changes that, leaving the value unmodified. We default to parsing this mystery event with the 1.0 spec. When the event is validated with `event.validate()` we return `false`. One additional small change to eliminate a prettier warning about `parer` being previously declared. Fixes: cloudevents#332 Fixes: cloudevents#333 Signed-off-by: Lance Ball <lball@redhat.com>
Even if the specversion is totally invalid, we should not change the value received in an incoming `Message`. Previously we defaulted to 1.0 if we did not recognize the version number. This commit changes that, leaving the value unmodified. We default to parsing this mystery event with the 1.0 spec. When the event is validated with `event.validate()` we return `false`. One additional small change to eliminate a prettier warning about `parer` being previously declared. Fixes: #332 Fixes: #333 Signed-off-by: Lance Ball <lball@redhat.com>
Even if the specversion is totally invalid, we should not change the value received in an incoming `Message`. Previously we defaulted to 1.0 if we did not recognize the version number. This commit changes that, leaving the value unmodified. We default to parsing this mystery event with the 1.0 spec. When the event is validated with `event.validate()` we return `false`. One additional small change to eliminate a prettier warning about `parer` being previously declared. Fixes: cloudevents#332 Fixes: cloudevents#333 Signed-off-by: Lance Ball <lball@redhat.com>
Describe the Bug
Does not throw if event doesn't have a
specversion
attribute, and fallbacks to1.0
. The spec says that thespecversion
attribute is mandatory, so I think this library should fail when it's missing, instead of "magically" falling back.Steps to Reproduce
Receiver.accept({ 'Content-Type': 'application/cloudevents+json' }, { id: 'foo', source: 'foo', type: 'foo' });
console.error
saying it will fallback to1.0
Expected Behavior
It should throw, since the
specversion
attribute is missingThe text was updated successfully, but these errors were encountered: