seriousme / fastify-openapi-glue

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

Schema validation #506

Closed shayff closed 1 year ago

shayff commented 1 year ago

I'm not sure if this question related to the plugin or the fastify itself. I have the following example: { "in": "formData", "name": "name", "type": "string", "required": true, "maxLength": 30, },

I see that I did get validation for the property and the type but not for the maxLength, any reason why?

seriousme commented 1 year ago

Hi,

thanks for asking !

As OpenApi V3 does not have a "formData" parameter I presume you are using V2.

Looking at the specification of the parameter object in V2 . Looking at https://spec.openapis.org/oas/v2.0#parameter-object I noticed that the current V2 parser implementation is missing the fields listed under: If [in](https://spec.openapis.org/oas/v2.0#parameterIn) is any value other than "body":

In V3 this problem does not occur as the schema items are all listed under a schema property. https://spec.openapis.org/oas/v3.1.0#parameter-object

So my first advice would be to migrate your spec to V3.x as this will make it also more future proof ;-)

In the meantime I will try to add the missing fields to the V2 parser.

Hope this helps ! Hans

seriousme commented 1 year ago

Released as 4.3.2 on NPM. Hope this helps ! Please reopen the issue if it doesn't work for you ! (Github autocloses an issue when its mentioned in a PR that is merged)

Kind regards, Hans