Multipart requestBody: required properties are blocking valid request from SwaggerUI
Hello ,
from the below APiSpec 3.0 ( myapi.yaml)
post:
...
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
contract:
description: use a Contract template object
$ref: '#/components/schemas/Contract'
contractors:
type: array
items:
$ref: '#/components/schemas/ContractorWithMode'
pdfparts:
type: array
items:
type: string
format: binary
appendixParts:
type: array
items:
type: string
format: binary
required:
- contract
- contractors
- pdfparts
we can see some required properties on the multipart object properties. ( e.g. contract, contractors, pdfparts)
When a request is built from SwaggerUI , With all required prop fullfilled , We have this error : { "errors": "request.body should have required property 'contract', request.body should have required property 'contractors', request.body should have required property 'pdfparts'" }
curl request built from SwaggerUI :
curl -X POST "http://localhost:3001/api/v4/transaction/fromscratch?start=false" -H "accept: multipart/form-data" -H "j_token: 5699057|EK3UH8/OpRcBihYF895e3/f6O1enTcI9" -H "Content-Type: multipart/form-data" -F "contract={
"name": "mon_premier_contrat",
"contract_definition_id": 2,
...
"role": "string"
}" -F "pdfparts=@response_1615314896818.pdf;type=application/pdf" -F "pdfparts=@smartfields_signature.pdf;type=application/pdf" -F "appendixParts=@save ssh key.PNG;type=image/png"
Will need to look into this. As a workaround, you can ignore validation on this route using ignorePaths
Will need to look into this. As a workaround, you can ignore validation on this route using ignorePaths
Sure , thanks !
Hi @cdimascio , I ran into the same problem. Did you already have time to look into this?
Specifically it happens if I set fileUploader: false. If it don't set this, no errors are shown, but the content of the form is not present on the body.
Specifically it happens if I set fileUploader: false. If it don't set this, no errors are shown, but the content of the form is not present on the body.
I get the same behavior with fileUploader: false, but without specifying the fileUploader option, the request is validated and the body is correctly received, req.files is also filled with uploads items
See this issue for a workaround :
https://github.com/cdimascio/express-openapi-validator/issues/820
Same here, not working and throwing error:
Error: Unexpected end of form
at Multipart._final (/var/local/acp/dashboards/node_modules/busboy/lib/types/multipart.js:588:17)
at callFinal (node:internal/streams/writable:698:12)
at prefinish (node:internal/streams/writable:710:7)
at finishMaybe (node:internal/streams/writable:720:5)
at Multipart.Writable.end (node:internal/streams/writable:634:5)
at onend (node:internal/streams/readable:705:10)
at processTicksAndRejections (node:internal/process/task_queues:77:11)