Skip to content

Commit

Permalink
fix consumes swagger-api#995
Browse files Browse the repository at this point in the history
  • Loading branch information
bodnia committed Apr 7, 2017
1 parent 169fced commit 51244af
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ export function buildRequest({
req.headers.accept = responseContentType
}

if (requestContentType) {
req.headers['content-type'] = requestContentType
}

// Add values to request
arrayOrEmpty(operation.parameters) // operation parameters
.concat(arrayOrEmpty(spec.paths[pathName].parameters)) // path parameters
Expand All @@ -123,6 +119,20 @@ export function buildRequest({
}
})

if (Array.isArray(operation.parameters)) {
if (requestContentType) {
req.headers['content-type'] = requestContentType
} else if (Array.isArray(operation.consumes)) {
req.headers['content-type'] = operation.consumes[0]
} else if (Array.isArray(operation.consumes)) {

This comment has been minimized.

Copy link
@ponelat

ponelat Apr 10, 2017

i think you mean spec.consumes here.

This comment has been minimized.

Copy link
@bodnia

bodnia Apr 10, 2017

Author Owner

Yes, you are right

req.headers['content-type'] = spec.consumes[0]
} else if (operation.parameters.filter((p)=> p.type === "file").length) {
req.headers['content-type'] = "multipart/form-data"
} else if (operation.parameters.filter((p)=> p.in === "formData").length) {
req.headers = "application/x-www-form-urlencoded"
}
}

// Add securities, which are applicable
req = applySecurities({request: req, securities, operation, spec})
// Will add the query object into the URL, if it exists
Expand Down

0 comments on commit 51244af

Please sign in to comment.