PayU / openapi-validator-middleware

Input validation using Swagger (Open API) and ajv
Apache License 2.0
144 stars 50 forks source link

Fastify integration fails when using fastify-multipart #193

Open Outc4sted opened 1 year ago

Outc4sted commented 1 year ago

I have a fastify project that is using fastify-multipart for a file upload endpoint. With fastify-multipart registered, all requests sent to my api, including endpoints that have nothing to do with files, will return an error from the openapi-validator:

šŸš€ ~ requestFilesExtractor.js
šŸš€ ~ req.file: [AsyncFunction: getMultipartFile]
šŸš€ ~ req.files: [AsyncGeneratorFunction: getMultipartFiles]
šŸš€ ~ app.setErrorHandler ~ error: TypeError: files.push is not a function
    at module.exports (C:\wrkspc\...\app\node_modules\openapi-validator-middleware\src\utils\requestFilesExtractor.js:7:19)

requestFilesExtractor.js file checks if req.file or req.files exists, and then proceeds to do other stuff. When fastify-multipart is registered, req.file and req.files are async functions and so they pass the check for existence, but then the proceeding logic bombs out when it tries handle them.

This has probably something to do with openapi-validator using express/multer under the hood but I'm not sure of a path forward except maybe having to install fastify-express along with express/multer and redoing my controller logic for handling files..