ErikWittern / openapi-snippet

Generates code snippets for given Swagger / Open API documents
MIT License
115 stars 66 forks source link

Fix bug when generating multipart/form-data requests #73

Closed bpross closed 2 years ago

bpross commented 2 years ago

multipart/form-data requests work for simple requests where values are of type string. However, if the values are richer data types like array or object the generation will fail with error:

  source.on('error', function() {});
         ^

TypeError: source.on is not a function
    at Function.DelayedStream.create (~/src/openapi-snippet/node_modules/delayed-stream/lib/delayed_stream.js:33:10)
    at FormData.CombinedStream.append (~/src/openapi-snippet/node_modules/combined-stream/lib/combined_stream.js:45:37)
    at FormData.append (~/src/openapi-snippet/node_modules/form-data/lib/form_data.js:68:3)
    at ~/src/openapi-snippet/node_modules/httpsnippet/src/index.js:111:16
    at Array.forEach (<anonymous>)
    at HTTPSnippet.prepare (~/src/openapi-snippet/node_modules/httpsnippet/src/index.js:110:33)
    at ~//src/openapi-snippet/node_modules/httpsnippet/src/index.js:48:31
    at validate (~/src/openapi-snippet/node_modules/har-validator/lib/async.js:29:12)
    at Object.exports.request (~/src/openapi-snippet/node_modules/har-validator/lib/async.js:96:10)
    at ~/src/openapi-snippet/node_modules/httpsnippet/src/index.js:43:14

This comment: https://github.com/request/request/issues/2366#issuecomment-292110690 confirms that the value must be of type string, Buffer or Stream.

Changes:

bpross commented 2 years ago

@ErikWittern I found a small bug with my changes when running it through our code base. Please consider this for inclusion when you have a moment.

Thank you!