-
Notifications
You must be signed in to change notification settings - Fork 70
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
feat: add a constructor parameter for loose validation #328
Conversation
Or maybe it is just called |
I'd rather not have implicit validation unless explicitly requested by the user. |
Then what's the point of having a module that is trying to adhere to a spec if it is off by default? |
I would expect a separate method for validation. Or at least be optional. Spec: https://github.com/cloudevents/spec/blob/master/SDK.md#compose-an-event A common way to do this would be: const ce = new CloudEvent({...});
const isValid = ce.isValid() // true or false
if (!isValid) {
console.log('Not a valid CloudEvent');
}
// or...
try {
ce.validate();
} catch (e) {
console.error(e);
} I would not imagine myself doing: let ce;
try {
ce = new CloudEvent({...}, true);
} catch (e) {
console.log(e)
} There's still lots of reason to use the module like calling calling |
I tend to agree with you in principle here @lholmquist. That said, a close reading of the spec makes me think that it's acceptable to default to not be strict. Specifically, https://github.com/cloudevents/spec/blob/master/SDK.md#validation only mentions that an SDK must make it possible to validate a given Event per a spec. This implies that having invalid events is a possibility, and potentially expected. When I think about possible friction that a developer might experience when starting to work with this SDK, I can see how easy it might be to get confused or frustrated if you're testing things with an invalid event and just don't know it - and strict validation is on by default, but there's no obvious way to know this. In spite of my tendency to prefer strict adherence to the spec always, I think maybe in this case, making the easy path as easy as possible, while providing for a simple way to remain strict could be a good thing. I don't like what it means for our tests though. By defaulting to loose validation, I think most if not all of our existing tests would need to be modified. Maybe we can get a discussion going in the #cloudeventssdk slack to see what others think. |
That sounds reasonable |
Yeah, its not a clear-cut problem. I don't know what the spec says about passing invalid CEs (they should probably work unless there is a fatal issue).
Checking others with slack sgtm. Another rationale for separate validation is because we may have already validated the CloudEvent (maybe from a different sdk, when cloning, already validated in the server, etc). |
OK - I brought this issue to attention at the CE community Zoom call today and got some good feedback. Here's a proposal.
This accomplishes a few things
|
Thanks for investigating :) Sounds fine. My opinion is a little different (validation should be explicitly requested by the user, not done in certain cases), but the above proposal sounds fine so long as folks don't get unexpected errors. |
This commit adds a second, optional boolean parameter to the `CloudEvent` constructor. When `false` is provided, the event constructor will not perform validation of the event properties, values and extension names. Fixes: cloudevents#325 Signed-off-by: Lance Ball <lball@redhat.com>
This commit modifies the ValidationError class so that the error message string includes the JSON.stringified version of any schema validation errors. It also makes the HTTP.toEvent() function create CloudEvent objects with loose/no validation. Incorporates comments from cloudevents#328 Signed-off-by: Lance Ball <lball@redhat.com>
252555f
to
60b22a7
Compare
@cloudevents/sdk-javascript-maintainers I have made the changes noted in the comments. You can see the |
@lance I think this is ready to be merged? |
* feat: add a constructor parameter for loose validation This commit adds a second, optional boolean parameter to the `CloudEvent` constructor. When `false` is provided, the event constructor will not perform validation of the event properties, values and extension names. This commit also modifies the ValidationError class so that the error message string includes the JSON.stringified version of any schema validation errors. It also makes the HTTP.toEvent() function create CloudEvent objects with loose/no validation. Incorporates comments from cloudevents#328 Fixes: cloudevents#325 Signed-off-by: Lance Ball <lball@redhat.com>
* feat: add a constructor parameter for loose validation This commit adds a second, optional boolean parameter to the `CloudEvent` constructor. When `false` is provided, the event constructor will not perform validation of the event properties, values and extension names. This commit also modifies the ValidationError class so that the error message string includes the JSON.stringified version of any schema validation errors. It also makes the HTTP.toEvent() function create CloudEvent objects with loose/no validation. Incorporates comments from #328 Fixes: #325 Signed-off-by: Lance Ball <lball@redhat.com>
* chore(example): Replaced body parser with express JSON parser (cloudevents#334) Signed-off-by: Philip Hayes <phayes@redhat.com> Co-authored-by: Philip Hayes <phayes@redhat.com> * fix: upgrade cloudevents from 3.0.1 to 3.1.0 (cloudevents#335) Snyk has created this PR to upgrade cloudevents from 3.0.1 to 3.1.0. See this package in npm: https://www.npmjs.com/package/cloudevents See this project in Snyk: https://app.snyk.io/org/lance/project/cb2960b0-db0c-4e77-9ab2-e78efded812e?utm_source=github&utm_medium=upgrade-pr Co-authored-by: snyk-bot <snyk-bot@snyk.io> Signed-off-by: Lucas Holmquist <lholmqui@redhat.com> * feat: add a constructor parameter for loose validation (cloudevents#328) * feat: add a constructor parameter for loose validation This commit adds a second, optional boolean parameter to the `CloudEvent` constructor. When `false` is provided, the event constructor will not perform validation of the event properties, values and extension names. This commit also modifies the ValidationError class so that the error message string includes the JSON.stringified version of any schema validation errors. It also makes the HTTP.toEvent() function create CloudEvent objects with loose/no validation. Incorporates comments from cloudevents#328 Fixes: cloudevents#325 Signed-off-by: Lance Ball <lball@redhat.com> Co-authored-by: Philip Hayes <philip@deewhy.ie> Co-authored-by: Philip Hayes <phayes@redhat.com> Co-authored-by: snyk-bot <snyk-bot@snyk.io> Co-authored-by: Lance Ball <lball@redhat.com>
* feat: add a constructor parameter for loose validation This commit adds a second, optional boolean parameter to the `CloudEvent` constructor. When `false` is provided, the event constructor will not perform validation of the event properties, values and extension names. This commit also modifies the ValidationError class so that the error message string includes the JSON.stringified version of any schema validation errors. It also makes the HTTP.toEvent() function create CloudEvent objects with loose/no validation. Incorporates comments from cloudevents#328 Fixes: cloudevents#325 Signed-off-by: Lance Ball <lball@redhat.com>
* feat: add a constructor parameter for loose validation This commit adds a second, optional boolean parameter to the `CloudEvent` constructor. When `false` is provided, the event constructor will not perform validation of the event properties, values and extension names. This commit also modifies the ValidationError class so that the error message string includes the JSON.stringified version of any schema validation errors. It also makes the HTTP.toEvent() function create CloudEvent objects with loose/no validation. Incorporates comments from #328 Fixes: #325 Signed-off-by: Lance Ball <lball@redhat.com>
Proposed Changes
strict
toCloudEvent
constructor, defaulting totrue
.strict
toCloudEvent.cloneWith()
defaulting totrue
strict
is falseDescription
This commit adds a second, optional boolean parameter to the
CloudEvent
constructor. When
false
is provided, the event constructor will notperform validation of the event properties, values and extension names.
As I am writing this, I wonder if it will be less error prone to default to
false
and call the parameter
looseValidation
.