Skip to content

Commit e250dd3

Browse files
committed
Fix failing tests due to parameter identification change
1 parent 710c92b commit e250dd3

File tree

3 files changed

+40
-38
lines changed

3 files changed

+40
-38
lines changed

src/execute.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ export function buildRequest({
115115
.concat(arrayOrEmpty(path.parameters)) // path parameters
116116
.forEach((parameter) => {
117117
const builder = parameterBuilders[parameter.in]
118-
let value = parameter.value
118+
let value
119119

120120
if (parameter.in === 'body' && parameter.schema && parameter.schema.properties) {
121121
value = parameters
122122
}
123123

124+
value = parameter && parameter.name && parameters[`${parameter.name}-${parameter.in}`]
125+
124126
if (typeof parameter.default !== 'undefined' && typeof value === 'undefined') {
125127
value = parameter.default
126128
}

test/execute.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ describe('execute', () => {
146146
}
147147

148148
// When
149-
const req = buildRequest({spec, operationId: 'getMe', parameters: {petId: 123}})
149+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'petId-query': 123}})
150150

151151
// Then
152152
expect(req).toEqual({
@@ -177,7 +177,7 @@ describe('execute', () => {
177177
}
178178

179179
// When
180-
const req = buildRequest({spec, operationId: 'getMe', parameters: {fields: '[articles]=title'}})
180+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'fields-query': '[articles]=title'}})
181181

182182
// Then
183183
expect(req).toEqual({
@@ -231,8 +231,8 @@ describe('execute', () => {
231231
spec,
232232
operationId: 'getMe',
233233
parameters: {
234-
false: false,
235-
zero: 0
234+
'false-query': false,
235+
'zero-query': 0
236236
}
237237
})
238238

@@ -265,7 +265,7 @@ describe('execute', () => {
265265
}
266266

267267
// When
268-
const req = buildRequest({spec, operationId: 'getMe', parameters: {petId: true}})
268+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'petId-query': true}})
269269

270270
// Then
271271
expect(req).toEqual({
@@ -395,7 +395,7 @@ describe('execute', () => {
395395
}
396396

397397
// When
398-
const req = buildRequest({spec, operationId: 'getMe', parameters: {petId: [1, 2, 3]}})
398+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'petId-formData': [1, 2, 3]}})
399399

400400
// Then
401401
expect(req.body).toEqual('petId=1,2,3')
@@ -458,7 +458,7 @@ describe('execute', () => {
458458
}
459459

460460
// When
461-
const req = buildRequest({spec, operationId: 'getMe', parameters: {status: false}})
461+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'status-query': false}})
462462

463463
// Then
464464
expect(req).toEqual({
@@ -538,7 +538,7 @@ describe('execute', () => {
538538
}
539539
}
540540

541-
const req = buildRequest({spec, operationId: 'loginUser', parameters: {username: 'fred', password: 'meyer'}})
541+
const req = buildRequest({spec, operationId: 'loginUser', parameters: {'username-query': 'fred', 'password-query': 'meyer'}})
542542

543543
expect(req).toEqual({
544544
url: 'http://swagger.io/v1/one?username=fred&password=meyer',
@@ -618,7 +618,7 @@ describe('execute', () => {
618618
const req = buildRequest({
619619
spec,
620620
operationId: 'postMe',
621-
parameters: {file: 'test'}})
621+
parameters: {'file-formData': 'test'}})
622622

623623
// Then
624624
expect(req).toEqual({
@@ -651,7 +651,7 @@ describe('execute', () => {
651651
const req = buildRequest({
652652
spec,
653653
operationId: 'postMe',
654-
parameters: {file: 'test'}})
654+
parameters: {'file-formData': 'test'}})
655655

656656
// Then
657657
expect(req).toEqual({
@@ -685,7 +685,7 @@ describe('execute', () => {
685685
const req = buildRequest({
686686
spec,
687687
operationId: 'postMe',
688-
parameters: {file: 'test'}})
688+
parameters: {'file-formData': 'test'}})
689689

690690
// Then
691691
expect(req).toEqual({
@@ -752,10 +752,10 @@ describe('execute', () => {
752752
const req = buildRequest({spec,
753753
operationId: 'getMe',
754754
parameters: {
755-
head: 'justTheHead',
756-
two: '2',
757-
body: {json: 'rulez'},
758-
question: 'answer'
755+
'head-header': 'justTheHead',
756+
'two-path': '2',
757+
'body-body': {json: 'rulez'},
758+
'question-query': 'answer'
759759
}})
760760

761761
// Then
@@ -783,7 +783,7 @@ describe('execute', () => {
783783
spec,
784784
operationId: 'makeMe',
785785
parameters: {
786-
body: {
786+
'body-body': {
787787
one: 1,
788788
}
789789
}})
@@ -832,7 +832,7 @@ describe('execute', () => {
832832
spec,
833833
operationId: 'makeMe',
834834
parameters: {
835-
body: {
835+
'body-body': {
836836
one: 1,
837837
two: {
838838
three: 3
@@ -859,7 +859,7 @@ describe('execute', () => {
859859
spec,
860860
operationId: 'makeMe',
861861
parameters: {
862-
body: 'hello'
862+
'body-body': 'hello'
863863
}
864864
})
865865

@@ -1083,7 +1083,7 @@ describe('execute', () => {
10831083
}
10841084

10851085
// When
1086-
const req = buildRequest({spec, operationId: 'getMe', parameters: {petId: ['a,b']}})
1086+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'petId-query': ['a,b']}})
10871087

10881088
// Then
10891089
expect(req).toEqual({
@@ -1129,7 +1129,7 @@ describe('execute', () => {
11291129
}
11301130

11311131
// When
1132-
const req = buildRequest({spec, operationId: 'getMe', parameters: {ids: [1, 2, 3], 'the names': ['a,b', 'mary']}})
1132+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'ids-query': [1, 2, 3], 'the names-query': ['a,b', 'mary']}})
11331133

11341134
// Then
11351135
expect(req).toEqual({
@@ -1164,7 +1164,7 @@ describe('execute', () => {
11641164
}
11651165

11661166
// When
1167-
const req = buildRequest({spec, operationId: 'getMe', parameters: {petId: [1, 2, 3]}})
1167+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'petId-query': [1, 2, 3]}})
11681168

11691169
// Then
11701170
expect(req).toEqual({
@@ -1199,7 +1199,7 @@ describe('execute', () => {
11991199
}
12001200

12011201
// When
1202-
const req = buildRequest({spec, operationId: 'getMe', parameters: {petId: [1, 2, 3]}})
1202+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'petId-query': [1, 2, 3]}})
12031203

12041204
// Then
12051205
expect(req).toEqual({
@@ -1234,7 +1234,7 @@ describe('execute', () => {
12341234
}
12351235

12361236
// When
1237-
const req = buildRequest({spec, operationId: 'getMe', parameters: {petId: [1, 2, 3]}})
1237+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'petId-query': [1, 2, 3]}})
12381238

12391239
// Then
12401240
expect(req).toEqual({
@@ -1269,7 +1269,7 @@ describe('execute', () => {
12691269
}
12701270

12711271
// When
1272-
const req = buildRequest({spec, operationId: 'getMe', parameters: {petId: [1, 2, 3]}})
1272+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'petId-query': [1, 2, 3]}})
12731273

12741274
// Then
12751275
expect(req).toEqual({
@@ -1304,7 +1304,7 @@ describe('execute', () => {
13041304
}
13051305

13061306
// When
1307-
const req = buildRequest({spec, operationId: 'getMe', parameters: {name: ['john', 'smith']}})
1307+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'name-query': ['john', 'smith']}})
13081308

13091309
// Then
13101310
expect(req).toEqual({
@@ -1372,11 +1372,11 @@ describe('execute', () => {
13721372
spec: spec2,
13731373
operationId: 'getBlob',
13741374
parameters: {
1375-
bodyParam: {
1375+
'bodyParam-body': {
13761376
name: 'johny',
13771377
id: '123'
13781378
},
1379-
someQuery: 'foo',
1379+
'someQuery-query': 'foo',
13801380
}})
13811381

13821382

@@ -1393,7 +1393,7 @@ describe('execute', () => {
13931393
})
13941394

13951395
it('should not add values of body parameters to the URL', function () {
1396-
const req = buildRequest({spec, operationId: 'postMe', parameters: {petId: 123}})
1396+
const req = buildRequest({spec, operationId: 'postMe', parameters: {'petId-body': 123}})
13971397

13981398

13991399
expect(req).toEqual({
@@ -1449,7 +1449,7 @@ describe('execute', () => {
14491449
})
14501450

14511451
it('should generate a request with body parameter', function () {
1452-
const req = buildRequest({spec, operationId: 'deleteMe', parameters: {petId: 123}})
1452+
const req = buildRequest({spec, operationId: 'deleteMe', parameters: {'petId-body': 123}})
14531453

14541454
expect(req).toEqual({
14551455
url: 'http://swagger.io/v1/one',
@@ -1481,7 +1481,7 @@ describe('execute', () => {
14811481
}
14821482
}
14831483

1484-
const req = buildRequest({spec, operationId: 'deleteMe', parameters: {api_key: 123}})
1484+
const req = buildRequest({spec, operationId: 'deleteMe', parameters: {'api_key-header': 123}})
14851485

14861486
expect(req).toEqual({
14871487
url: 'http://swagger.io/v1/one',
@@ -1602,7 +1602,7 @@ describe('execute', () => {
16021602
}
16031603
}
16041604

1605-
const req = buildRequest({spec, operationId: 'getMe', parameters: {id: '123'}})
1605+
const req = buildRequest({spec, operationId: 'getMe', parameters: {'id-path': '123'}})
16061606

16071607
expect(req).toEqual({
16081608
url: 'http://swagger.io/v1/123',
@@ -1641,7 +1641,7 @@ describe('execute', () => {
16411641
}
16421642
}
16431643

1644-
const req = buildRequest({spec, operationId: 'getPetsById', parameters: {id: 123, test: 567}})
1644+
const req = buildRequest({spec, operationId: 'getPetsById', parameters: {'id-path': 123, 'test-query': 567}})
16451645

16461646
expect(req).toEqual({
16471647
url: 'http://swagger.io/v1/pet/123?test=567',
@@ -1679,7 +1679,7 @@ describe('execute', () => {
16791679
}
16801680
}
16811681

1682-
const req = buildRequest({spec, operationId: 'getPetsById', parameters: {id: 123, test: 567}})
1682+
const req = buildRequest({spec, operationId: 'getPetsById', parameters: {'id-path': 123, 'test-query': 567}})
16831683

16841684
expect(req).toEqual({
16851685
url: 'http://swagger.io/v1/pet/123?test=567',
@@ -1708,7 +1708,7 @@ describe('execute', () => {
17081708
}
17091709
}
17101710

1711-
const req = buildRequest({spec, operationId: 'deleteMe', parameters: {id: 'foo/bar'}})
1711+
const req = buildRequest({spec, operationId: 'deleteMe', parameters: {'id-path': 'foo/bar'}})
17121712

17131713
expect(req).toEqual({
17141714
url: 'http://swagger.io/v1/foo%2Fbar',
@@ -1742,7 +1742,7 @@ describe('execute', () => {
17421742
const req = buildRequest({spec,
17431743
requestContentType: 'application/x-www-form-urlencoded',
17441744
operationId: 'postMe',
1745-
parameters: {petId: 'id'}})
1745+
parameters: {'petId-formData': 'id'}})
17461746

17471747
expect(req).toEqual({
17481748
url: 'http://swagger.io/v1/one',

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ describe('constructor', () => {
467467
req.url = 'http://petstore.swagger.io/v2/pet/4'
468468
}
469469
}).then((client) => {
470-
client.apis.pet.getPetById({petId: 3}).then((data) => {
470+
client.apis.pet.getPetById({'petId-path': 3}).then((data) => {
471471
expect(data.body.id).toEqual(4)
472472
cb()
473473
})
@@ -481,7 +481,7 @@ describe('constructor', () => {
481481
res.body.id = 4
482482
}
483483
}).then((client) => {
484-
client.apis.pet.getPetById({petId: 3}).then((data) => {
484+
client.apis.pet.getPetById({'petId-path': 3}).then((data) => {
485485
expect(data.body.id).toEqual(4)
486486
cb()
487487
})

0 commit comments

Comments
 (0)