Skip to content

Commit

Permalink
fix: check if file in req.files is undefined
Browse files Browse the repository at this point in the history
Stops Express returning an empty 400 response early on when indexing the file object in a single file upload.
  • Loading branch information
Dakskihedron committed Jul 3, 2024
1 parent f0f2440 commit e99c0d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eight-bikes-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@openapi-generator-plus/typescript-express-passport-server-generator": patch
---

Check if file in req.files is undefined before indexing.
2 changes: 1 addition & 1 deletion templates/api.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function(app: Express, impl: t.{{className name}}Api) {
{{#if (isContentMultipart .)}}
if (req.files && !Array.isArray(req.files)) {
{{#each (fileUploadProperties schema.properties)}}
req.body[{{{stringLiteral name}}}] = req.files[{{{stringLiteral name}}}]{{#unless isArray}}[0]{{/unless}}
req.body[{{{stringLiteral name}}}] = req.files[{{{stringLiteral name}}}] ? req.files[{{{stringLiteral name}}}]{{#unless isArray}}[0]{{/unless}} : undefined
{{/each}}
}
return {{>frag/fromRequest schema prefix='v.'}}('body', req.body)
Expand Down

0 comments on commit e99c0d8

Please sign in to comment.