carlansley / swagger2

Loading, parsing and validating requests to HTTP services based on Swagger v2.0 documents
MIT License
25 stars 17 forks source link

Feat: support formData #22

Closed jeasonstudio closed 6 years ago

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 1bb2121e20ebaad098a783ee3eed3acd2ec6e876 on jeasonstudio:master into c83a25935dfd27602cbc83f4d1dab43ab7a2f3ad on carlansley:master.

jeasonstudio commented 6 years ago

A couple of things:

  1. can you remove the generated dist files from the PR
  2. add a unit test to cover the formData change

Done for these.

jeasonstudio commented 6 years ago

Waiting for the new version. Thx.

carlansley commented 6 years ago

just published new versions of swagger2 and swagger2-koa

alexbe commented 6 years ago

Hi, i got {"code":"SWAGGER_REQUEST_VALIDATION_FAILED","errors":[{"expected":{"type":"string"},"error":"data is the wrong type","where":"formData"},{"expected":{"type":"string"},"error":"data is the wrong type","where":"formData"}]}

Please patch it like this:

case 'formData':
-        value = (body || {})[parameter.name];
+       value = (body.fields || {})[parameter.name];

The reason is that the body object consist of two other objects fields:Object {id: 0, note: "blabla", …} files:Object {}

and has no parameter.name key

carlansley commented 6 years ago

@alexbe can you submit a PR for this that includes a test case.