-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
Strict contract responses #99
Comments
thanks for the issue @plastic-abubakr. |
prior to a recent fix, responses were allowing additional properties to pass validation. we could consider making this option again. is that what you are looking for? |
@plastic-abubakr ^ |
@cdimascio here is my use case: Lets say my response schema is define to return array of *Roles:
Roles data model has some additional properties defined, for example an id for each row. Problem is, I can not send the database query result as it is, and have to manually filter out any additional fields that are not supposed to be sent to the client. Right now, if i don't filter out the results, it will send out the following response to the client:
Where as the openapi schema is defiend to send only guid and label. I feel it should strip out extra fields which are not defined in response schema |
Got it. This makes sense. I'll add support for this. |
By all means add support for this: I understand the issue and the motivation 👍 This does expand the scope of this library though, a library which has Transformation of either the input or the output to conform to some schema is a distinct concern. Even if the transformation feature is optional — and I expect it'll be off by default — adding this feature dilutes the focus of this library. It'd be helpful for some set of users, undoubtedly, but it also adds weight that's not directly relevant to what this library is about: validation. Perhaps there's a distinct library that could be developed — Like I say, do add support for this if you're so minded 👍 😃 |
@richdouglasevans I tend to disagree. The widely used JSON validation library "joi" also decided to support "stripUnknown" to strip unknown fields from a payload. Users like me would end up in adding Joi just to implement a sanitizer to request and response. That would mean I have to maintain Joi model definitions along with the openAPI definition. Personally I would like to see this feature ( but would disable it by default). |
#99 option to remove additional props from responses
in v2.14.1 you can get the behavior you are looking for with the following option:
This will validate responses, but remove any additionalProperties that would not pass schema validation. |
This does not seem to be working
|
@plastic-abubakr I have a couple of tests to demonstrate this functionality. Perhaps have a quick look to see if your look similar. I believe this should work now, the caveat is that Here are some examples in the test suite
Hopefully, you're missing something, if not please pass along the details and i'll look into |
Is there a configuration that I'm missing that strips out any fields that are not defined in the response schema?
The text was updated successfully, but these errors were encountered: