jhthorsen / mojolicious-plugin-openapi

OpenAPI / Swagger plugin for Mojolicious
54 stars 44 forks source link

Strict input checking? #207

Closed augensalat closed 3 years ago

augensalat commented 3 years ago

(By default?) this plugin does permissive validation: Any fields that are not specified in the OpenAPI spec are ignored.

Is it possible to switch validation to be "strict" instead?

Otherwise this would be my feature request.

jberger commented 3 years ago

While this could be a feature that the plugin could support, I think in the end you'd want this to be in your spec file. For something like a schema it is easy with additionalProperties: false but for say query parameters it isn't as easy. Here's a suggestion I found: https://stackoverflow.com/a/49199240/468327 (note that that question is actually slightly harder, trying to answer for mutually exclusive query parameters but your question is a subset of that I think).

jhthorsen commented 3 years ago

Can you please provide a real world usecase?

The input parameters are tracked, so it’s doable. https://github.com/jhthorsen/mojolicious-plugin-openapi/blob/c9408c833e5822b2538430fbdc804c3c795ea4eb/lib/Mojolicious/Plugin/OpenAPI/Parameters.pm#L35

augensalat commented 3 years ago

While this could be a feature that the plugin could support, I think in the end you'd want this to be in your spec file. For something like a schema it is easy with additionalProperties: false [...]

@jberger, that was exactly the option I was missing. Tested, works, problem solved. Thank you very much!