Closed tflolo closed 12 months ago
@tflolo - Do any of your security handlers depend on form values submitted as part of the multipart/form-data
request? From the OpenAPI schema you posted, it doesn't look this this would be the case, unless you removed those values before pasting here?
@mdmower - None of my security handlers does anything other than check for a valid session. The code i posted is complete, and only thing i change between runs is the version of express-openapi-validator from 5.0.1 to 5.1.0. I can try to move multipartMiddlware after securityMiddleware in 5.0.1 and see if that works.
@tflolo - Is there a chance that you recently updated your openapi schema to support multiple uploads via I was able to reproduce the same error as you, but the error I found also exists in version 5.0.5. To see if we're observing the same error, when version 5.1.0 is installed, could you temporarily update the following file and retest?oneOf
schema?
in node_modules/express-openapi-validator/dist/middlewares/openapi.request.validator.js
, replace old line 131:
const type = (_c = (_b = (_a = schemaBody === null || schemaBody === void 0 ? void 0 : schemaBody.properties) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.properties[key]) === null || _c === void 0 ? void 0 : _c.type;
with new line:
const type = (_d = (_c = (_b = (_a = schemaBody === null || schemaBody === void 0 ? void 0 : schemaBody.properties) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.type;
I've drafted PR #878 (which outputs the compiled JS above) but would like confirmation that it resolves the issue.
UPDATE: I just noticed that your report says you updated from 5.0.1 to 5.1.0, so this is starting to make sense. Support for nested JSON in multipart bodies was added in 5.0.2. See https://github.com/cdimascio/express-openapi-validator/commit/e5cb5d68607fa0ad37c074363c471bb11d7791bb .
@mdmower The error changed,
status: 500,
text: '{"message":"_d is not defined"}',
method: 'POST',
path: '/api/wave-log/upload'
I upgraded to 5.1.0 and copied the line 131 you posted
UPDATE: _d was not defined in the function, i defined it and now it works :)
UPDATE: _d was not defined in the function, i defined it and now it works :)
Thanks for fixing my derp. I'll request a review on the PR.
Describe the bug I upgraded to v5.1.0 from v5.0.1 to get the fix where multipartMiddleware is put after securityMiddleware. When i did this, the file is uploaded, but i get this error:
{ "message": "Cannot read properties of undefined (reading 'file')" }
And I no longer get to my requestHandler to handle req.files and furher work with the data.
To Reproduce Upgrade from 5.0.1 to 5.1.0
Actual behavior File gets uploaded, but throws an internal server error that stops the request from getting to my requesthandler
Expected behavior Expected the req.files to be populated with data about my uploaded files.
Examples and context jest tets with supertest: openApi def:
Request handler:
On v5.0.1
I get
Only changing to v5.1.0 i get
and of course not coming to my requestHandler, the file still uploads.