mikestead / swagger-routes

Generate Express or Restify route handlers from a Swagger specification
MIT License
20 stars 8 forks source link

formData required validation #26

Open fabricio-godoi opened 4 years ago

fabricio-godoi commented 4 years ago

Greetings everyone, I'm having problem when validation formData file upload with multer and swaggerRoutes. swagger.yml

parameters:
- in: "formData"
        type: "file"
        required: true
        name: "document"

The swaggerRoutes method returns this when validating the "required: true": "message": "formData requires property \"document\""

If I set required as false, the swaggerRotues continues without any problem.

Anyone have any ideas how to solve this?

russell-matt commented 4 years ago

@fabricio-godoi Were you sending through an accept header on your requests? I recently found in my own projects that the form data parsing fails if an accept header that is not "multipart/form-data" or "application/x-www-form-urlencoded" is sent on the request.

It's specifically coming from this line.

It seems like the accept header is incorrectly being used to determine whether the request will have form data or not; instead of the content-type header.

It will work as intended if no accept header is sent, or if an accept header like "*/*", "application/*" or "multipart/*" is used. However doing that as a work around seems ill advised.

fabricio-godoi commented 4 years ago

@russell-matt I was not providing the accept header, just the "content-type": "multipart/form-data". For now, I set the field as not required since I could not configure it properly, but I`ll keep in mind that workaround in future releases.

But the problem is with the swagger web interface that does not set up the accept header, so this workaround will not resolve all my problems :disappointed:

I hope that is fixed in the feature releases. Thank you for your response :smile: