Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/execute/oas3/build-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function (options, req) {
Object.keys(requestBody).forEach((k) => {
const val = requestBody[k]
req.form[k] = {
value: val
value: typeof val === 'object' ? JSON.stringify(val) : val
}
})
}
Expand Down
52 changes: 52 additions & 0 deletions test/oas3/execute/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,58 @@ describe('buildRequest - OpenAPI Specification 3.0', function () {
})
})

it('should stringify object values of form data bodies', function () {
// Given
const spec = {
openapi: '3.0.0',
servers: [
{
url: 'http://petstore.swagger.io/v2',
name: 'Petstore'
}
],
paths: {
'/one': {
get: {
operationId: 'getOne',
requestBody: {
content: {
'application/x-www-form-urlencoded': {
schema: {
type: 'object'
}
}
}
}
}
}
}
}

// when
const req = buildRequest({
spec,
operationId: 'getOne',
requestBody: {
a: 1,
b: {
c: 3,
d: 4
}
}
})

expect(req).toEqual({
method: 'GET',
url: 'http://petstore.swagger.io/v2/one',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'a=1&b=%7B%22c%22%3A3%2C%22d%22%3A4%7D'
})
})

it('should build a request for the given operationId with a requestBody, and not be overriden by an invalid Swagger2 body parameter value', function () {
// Given
const spec = {
Expand Down