One of the most powerful aspects of Zuplo is the programmable extensibility.
Recently somebody on our Discord channel asked if
we supported query parameter validation as we do
JSON Body validation.
We plan to add this soon as a built-in policy (which will use your OpenAPI
specification). However, I spent 20 minutes building a custom policy to
demonstrate how easy it would be to build a custom policy to support this while
you wait.
Here's how you would configure the policy
This defines a policy for a route (which can be reused on other routes) that
states there are four supported query parameters: foo, bar, wib and ble.
No additional query parameters are allowed.
Note that foo, bar and ble are required, whereas wib is optional.
Each has a different type specified, and the request will be rejected if the
data cannot be parsed as that type from the options int, number, string,
and boolean.
Here are some hits on that URL and associated error responses (status code 400):
Bad Request
Required query parameter 'foo' missing
Invalid value for query parameter 'bar': 'hey' is not a valid number
Invalid value for query parameter 'ble': '23' not a valid boolean value (expect 'true' or false')
Easy peasy - here's the code for that custom policy