-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow response object stripping according to schema #1723
Comments
Yes, this would be awesome. I assumed this was the default behavior, and after some investigation saw that in the response's Declarative response validation is an awesome Hapi feature. Letting that schema function as an actual gatekeeper beyond using it to serve or logging errors would be even better. My use-case for this is based on the notion that it's easier to scrub with Joi than to tweak data queries or to manually remove keys that I don't want in the response. It's a bit brain-dead, but it's also dead simple and absolutely and declaratively enforces how a response will look. It's both a form of testing and data protection. I can perform this same validation in the route handler, but that makes it less declarative. |
There's also a compatibility issue here with |
I'm just starting with hapijs so my opinion might not be relevant, but I believe that adding an option like:
would allow this change with breaking anything else. Apart from that, I also think that filtering keys based on schema would be a great addition, since it seems that everyone, one way or another, is stripping out values from their responses to avoid displaying private properties. |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
I'd like to be able to
reply
from a request handler with an object that has some extra keys other than its schema allows, with the resulting response containing only those keys that are allowed by the schema.Example:
validation: { stripUnknown: true }
response: { schema: Joi... }
specifieddoc
which has more keys than needed for the responsereply(doc)
internally validatesdoc
to satisfyresponse.schema
and returns resultCurrent behavior with the setup:
doc
validation succeeds, but final response contains keys not mentioned in the schema.Desired behavior:
doc
validation succeeds, and final response doesn't contain keys not mentioned in the schema.Related: #1639
The text was updated successfully, but these errors were encountered: