|Welcome to the Monastery|
Mojolicious::Plugin::OpenAPI strict or filter object representationby Veltro (Friar)
|on Mar 24, 2019 at 15:33 UTC||Need Help??|
Veltro has asked for the
wisdom of the Perl Monks concerning the following question:
I am looking for a possibility to indicate that the schema definition must be 'exact' in the sense that if more parameters are specified I want the validation to 'fail' for the request, and 'fail' or 'filtered' for the response (hopefully by specifying this in the OpenAPI spec). I wonder if anyone knows if this can be done in swagger 2.0 (or newer versions)?
As far as I understand now, swagger 2.0 allows you to tell that parameter are 'required' by defining the parameters like this (Just as an example a 'animal' object):
However, there is nothing that stops anyone from sending an animal with many more parameters other than 'animalid' or 'animalname' or could even add completely unrelated data in the request. Similarly it also does not stop the back-end from creating an object containing many more parameters and send those to the client as well.
What if I would send a 'user' object and I had accidentally created a database query resulting in an object containing the password as well (because let's say I was turning beer instead of coffee into code one night). I did not specify the password as a valid parameter in the spec, but it gets send anyhow! How could I potentially either block the entire response, or if desired, filter out the password and send the response with just those parameters that were specified in the spec?
Another reason why this would be desired is to detect typos, In case a parameter is optional and e.g. called animalname, but is send as animalName, this is not detected. But when the definition would have been taken 'strict' then this typo would have been detected. The response error could say something like: animalName is not a valid parameter!
I was digging through the entire OpenAPI spec, but have not been able to find anything. Has anyone found a solution for this?