@@ -305,6 +305,165 @@ describe('ServerlessAWSDocumentation', function() {
305
305
} ) ;
306
306
} ) ;
307
307
308
+ it ( 'should only add response methods with response headers to ApiGateway methods' , function ( ) {
309
+ this . serverlessMock . variables . service . custom . documentation . models = [ ] ;
310
+ this . serverlessMock . service . _functionNames = [ 'test' , 'blub' ] ;
311
+ this . serverlessMock . service . _functions = {
312
+ test : {
313
+ events : [ {
314
+ http : {
315
+ path : 'some/path' ,
316
+ method : 'post' ,
317
+ cors : true ,
318
+ private : true ,
319
+ documentation : {
320
+ methodResponses : [
321
+ {
322
+ statusCode : 200 ,
323
+ responseModels : {
324
+ 'application/json' : 'CreateResponse' ,
325
+ } ,
326
+ responseHeaders : [ {
327
+ name : 'x-header' ,
328
+ description : 'THE header' ,
329
+ } , {
330
+ name : 'x-other-header' ,
331
+ description : 'THE other header' ,
332
+ } ] ,
333
+ } ,
334
+ {
335
+ statusCode : 400 ,
336
+ responseModels : {
337
+ 'application/json' : 'ErrorResponse'
338
+ } ,
339
+ responseHeaders : [ {
340
+ name : 'x-header' ,
341
+ description : 'THE header' ,
342
+ } ] ,
343
+ } ,
344
+ {
345
+ statusCode : 404 ,
346
+ responseModels : {
347
+ 'application/json' : 'ErrorResponse'
348
+ } ,
349
+ responseHeaders : [ {
350
+ name : 'x-header' ,
351
+ description : 'THE header' ,
352
+ } ] ,
353
+ } ,
354
+ ] ,
355
+ }
356
+ } ,
357
+ } ] ,
358
+ } ,
359
+ blub : {
360
+ events : [ {
361
+ http : {
362
+ path : 'some/other/path' ,
363
+ method : 'get' ,
364
+ cors : true ,
365
+ private : true ,
366
+ documentation : {
367
+ methodResponses : [
368
+ {
369
+ statusCode : 204 ,
370
+ responseModels : {
371
+ 'application/json' : 'CrazyResponse' ,
372
+ } ,
373
+ responseHeaders : [ {
374
+ name : 'x-header' ,
375
+ description : 'THE header' ,
376
+ } , {
377
+ name : 'x-other-header' ,
378
+ description : 'THE other header' ,
379
+ } ] ,
380
+ } ,
381
+ ] ,
382
+ } ,
383
+ } ,
384
+ } ] ,
385
+ } ,
386
+ } ;
387
+
388
+ const resources = this . serverlessMock . service . provider . compiledCloudFormationTemplate . Resources ;
389
+ resources . someotherpath_get = {
390
+ some : 'other_configuration' ,
391
+ Properties : { } ,
392
+ } ;
393
+ resources . somepath_post = {
394
+ some : 'configuration' ,
395
+ Properties : { } ,
396
+ } ;
397
+
398
+ this . plugin . beforeDeploy ( ) ;
399
+
400
+ expect ( this . serverlessMock . service . provider . compiledCloudFormationTemplate ) . toEqual ( {
401
+ Resources : {
402
+ ExistingResource : {
403
+ with : 'configuration' ,
404
+ } ,
405
+ somepath_post : {
406
+ some : 'configuration' ,
407
+ DependsOn : [ 'CreateResponseModel' , 'ErrorResponseModel' ] ,
408
+ Properties : {
409
+ MethodResponses : [ {
410
+ StatusCode : 200 ,
411
+ ResponseModels : {
412
+ 'application/json' : 'CreateResponse' ,
413
+ } ,
414
+ ResponseParameters : {
415
+ 'method.response.header.x-header' : true ,
416
+ 'method.response.header.x-other-header' : true ,
417
+ } ,
418
+ } ,
419
+ {
420
+ StatusCode : 400 ,
421
+ ResponseModels : {
422
+ 'application/json' : 'ErrorResponse'
423
+ } ,
424
+ ResponseParameters : {
425
+ 'method.response.header.x-header' : true ,
426
+ } ,
427
+ } ,
428
+ {
429
+ StatusCode : 404 ,
430
+ ResponseModels : {
431
+ 'application/json' : 'ErrorResponse'
432
+ } ,
433
+ ResponseParameters : {
434
+ 'method.response.header.x-header' : true ,
435
+ } ,
436
+ } ] ,
437
+ } ,
438
+ } ,
439
+ someotherpath_get : {
440
+ some : 'other_configuration' ,
441
+ DependsOn : [ 'CrazyResponseModel' ] ,
442
+ Properties : {
443
+ MethodResponses : [ {
444
+ StatusCode : 204 ,
445
+ ResponseModels : {
446
+ 'application/json' : 'CrazyResponse' ,
447
+ } ,
448
+ ResponseParameters : {
449
+ 'method.response.header.x-header' : true ,
450
+ 'method.response.header.x-other-header' : true ,
451
+ } ,
452
+ } ] ,
453
+ }
454
+ } ,
455
+ } ,
456
+ Outputs : {
457
+ AwsDocApiId : {
458
+ Description : 'API ID' ,
459
+ Value : {
460
+ Ref : 'ApiGatewayRestApi' ,
461
+ } ,
462
+ }
463
+ } ,
464
+ } ) ;
465
+ } ) ;
466
+
308
467
it ( 'should only add request models to ApiGateway methods' , function ( ) {
309
468
this . serverlessMock . variables . service . custom . documentation . models = [ ] ;
310
469
this . serverlessMock . service . _functionNames = [ 'test' , 'blub' ] ;
0 commit comments