express-openapi-validator icon indicating copy to clipboard operation
express-openapi-validator copied to clipboard

Multipart requestBody: required properties are blocking valid request from SwaggerUI

Open mpoggicalinda opened this issue 4 years ago • 7 comments

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"

mpoggicalinda avatar Mar 23 '21 10:03 mpoggicalinda

Will need to look into this. As a workaround, you can ignore validation on this route using ignorePaths

cdimascio avatar Apr 04 '21 15:04 cdimascio

Will need to look into this. As a workaround, you can ignore validation on this route using ignorePaths

Sure , thanks !

mpoggicalinda avatar Apr 06 '21 07:04 mpoggicalinda

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.

mathiasmah avatar Jan 11 '22 16:01 mathiasmah

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

Fabiencdp avatar Feb 17 '22 11:02 Fabiencdp

See this issue for a workaround :

https://github.com/cdimascio/express-openapi-validator/issues/820

fredbonin avatar Mar 01 '23 17:03 fredbonin

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)

Bec-k avatar May 26 '23 13:05 Bec-k