seriousme / fastify-openapi-glue

A plugin for the Fastify webserver to autogenerate a Fastify configuration based on a OpenApi(v2/v3) specification.
MIT License
206 stars 33 forks source link

Validation of request body #601

Closed marcellusherlus closed 2 months ago

marcellusherlus commented 2 months ago

Hey first of thanks for the plugin and your hard work :)

I stumbled up on this phrase in your readme

Given an OpenApi specification Fastify-openapi-glue handles the fastify configuration of routes and validation schemas etc

I understood that this plugin will handle all the validation for me(depending of my openapi.yaml) but I am experiencing the problem, that the JSON Body of a POST Request will only check for missing attributes, but not if the attribute has the correct format e.g number instead of string.

Is this the intended behavior or am I doing something wrong in my application?

Thanks in advance

marcellusherlus commented 2 months ago

Okay this can be closed coerceTypes: true did the trick :)

seriousme commented 2 months ago

For completeness, see also: https://github.com/seriousme/fastify-openapi-glue/issues/338#issuecomment-1141379299

seriousme commented 2 months ago

And you might want to consider Postel's law:

"be conservative in what you do, be liberal in what you accept from others"

https://en.wikipedia.org/wiki/Robustness_principle