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
9 changes: 9 additions & 0 deletions src/execute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ export function buildRequest(options) {
throw new Error(`Required parameter ${parameter.name} is not provided`)
}

if (specIsOAS3 && parameter.schema && parameter.schema.type === 'object' && typeof value === 'string') {
try {
value = JSON.parse(value)
}
catch (e) {
throw new Error('Could not parse object parameter value string as JSON')
}
}

if (builder) {
builder({req, parameter, value, operation, spec})
}
Expand Down
39 changes: 39 additions & 0 deletions test/oas3/execute/style-explode/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,45 @@ describe('OAS 3.0 - buildRequest w/ `style` & `explode` - query parameters', fun
})
})

it('should handle building a query parameter in form/explode format, with a stringified object provided, if schema type is indicated', function () {
// Given
const spec = {
openapi: '3.0.0',
paths: {
'/users': {
get: {
operationId: 'myOperation',
parameters: [
{
name: 'id',
in: 'query',
schema: {
type: 'object'
}
}
]
}
}
}
}

// when
const req = buildRequest({
spec,
operationId: 'myOperation',
parameters: {
id: JSON.stringify(VALUE)
}
})

expect(req).toEqual({
method: 'GET',
url: `/users?role=admin&firstName=Alex&greeting=${SAFE_INPUT_RESULT}`,
credentials: 'same-origin',
headers: {},
})
})

it('should build a query parameter with escaped non-RFC3986 characters', function () {
// Given
const spec = {
Expand Down