Skip to content

Commit b2ea186

Browse files
committed
Change buildRequest method to handle both name format and name-in format for parameter values.
1 parent d2295d6 commit b2ea186

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/execute.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ export function buildRequest({
123123

124124
value = parameter && parameter.name && parameters[parameter.name]
125125

126+
if (typeof value === 'undefined') {
127+
// check for `name-in` formatted key
128+
value = parameter && parameter.name && parameters[`${parameter.name}-${parameter.in}`]
129+
}
130+
126131
if (typeof parameter.default !== 'undefined' && typeof value === 'undefined') {
127132
value = parameter.default
128133
}

test/execute.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,37 @@ describe('execute', () => {
13141314
headers: { }
13151315
})
13161316
})
1317+
1318+
it('should fall back to `name-in` format when a parameter cannot be found', function () {
1319+
// Given
1320+
const spec = {
1321+
host: 'swagger.io',
1322+
basePath: '/v1',
1323+
paths: {
1324+
'/one': {
1325+
get: {
1326+
operationId: 'getMe',
1327+
parameters: [{
1328+
name: 'name',
1329+
in: 'query',
1330+
type: 'string'
1331+
}]
1332+
}
1333+
}
1334+
}
1335+
}
1336+
1337+
// When
1338+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'name-query': 'john'}})
1339+
1340+
// Then
1341+
expect(req).toEqual({
1342+
url: 'http://swagger.io/v1/one?name=john',
1343+
method: 'GET',
1344+
credentials: 'same-origin',
1345+
headers: { }
1346+
})
1347+
})
13171348
})
13181349

13191350
describe('body', function () {

0 commit comments

Comments
 (0)