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
Websocket event schema #8218
Websocket event schema #8218
Conversation
Updating My Fork
pulling changes from master
merging changes from master branch into my forked repo
merging recent commits from master into my fork
Codecov Report
@@ Coverage Diff @@
## master #8218 +/- ##
==========================================
- Coverage 88.09% 88.08% -0.02%
==========================================
Files 248 248
Lines 9377 9369 -8
==========================================
- Hits 8261 8253 -8
Misses 1116 1116
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great thanks @zaldanaraul ! That looks very promising.
Please see my remarks, there's nothing significant, I think it's close to what we're after.
Also, I'm not sure how to do testing for the schema.
We've agreed to not write tests that confirm schema errors (simply to avoid maintanance cost, and validation schema engine is tested extensively on its own).
By tests we only confirm that valid configuration works, and all tests that are configured through runServerless
(see https://github.com/serverless/serverless/tree/master/test#unit-tests) are configured to crash whenever configuration error is approached in tested case.
Ideally such tests should also cover all supported configuration cases.
Unfortunately websockets, aside of integration tests, are not tested well via service configurations
Ideally would be to have its unit tests refactored, so they're solely based on runServerless
, but that's definitely not in scope of this PR (anyway PR that does that is defintely welcome)
Otherwise you may just test it manually, by configuring simple service, and testing configuration via sls print
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zaldanaraul great thanks for update! It looks very promising. Please see my remarks.
Also it'll be good to remove inline validation we have in event implementation (see e.g. errors removed here: https://github.com/serverless/serverless/pull/8230/files )
For websockets, validation seems to be implemented through the validate function defined here: Although it seems to check for things that the schema also checks for, the errors that it throws do seem clearer than the ones from the schema at this point. Also, because this function is simply included but not called in the
serverless/lib/plugins/aws/package/compile/events/websockets/index.js Lines 15 to 23 in 6f392b3
Please advise on how to proceed here :( |
Which errors exactly? In general we follow the rule to not duplicate schema validation with inline validation that validates very same things. Also schema errors are configured to be well descriptive
I don't think that we should remove that functions. In most cases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @zaldanaraul that looks really good! All that we miss, is what we've discussed in other comments (so restricting routeResponseSelectionExpression
to $default
, and stripping inline validation which covers what would be covered now by config schema validation)
I'll stick to this rule then. In that case I removed three inline validations from the
Also changed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks great @zaldanaraul ! Thank you
Closes: #8019
Hi this is my proposal for the websocket event schema. This is my first PR so sorry if I missed something basic!
Also, I'm not sure how to do testing for the schema. I did my own testing but I'm not sure how to do it within SLS. Maybe someone could provide some guidance (e.g. which files I should be working with to do the testing)? Thank you!