File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed
Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -185,6 +185,10 @@ describe('Example', () => {
185185 . addOperation ( HttpMethods . HEAD , {
186186 operationId : 'checkUserIdAvailableCommand' ,
187187 security : noSecurityRequirement ,
188+ responses : {
189+ 204 : new Response ( api , 'HeadUserResponseFound' ) ,
190+ 404 : new Response ( api , 'HeadUserResponseNotFound' ) ,
191+ } ,
188192 } )
189193 . addOperation ( HttpMethods . POST , {
190194 operationId : 'updateUserCommand' ,
Original file line number Diff line number Diff line change @@ -4,31 +4,35 @@ import type { Header } from './header.js';
44import { MediaType , type MediaTypeOptions } from './media-type.js' ;
55
66interface ResponseOptions {
7- content : MediaType | MediaTypeOptions ;
7+ content ? : MediaType | MediaTypeOptions ;
88 description ?: string ;
99 headers ?: Header [ ] ;
1010}
1111
1212export class Response extends Construct {
1313 private options : ResponseOptions ;
1414
15- private content : MediaType ;
15+ private content ? : MediaType | undefined ;
1616
17- constructor ( scope : Construct , id : string , options : ResponseOptions ) {
17+ constructor ( scope : Construct , id : string , options : ResponseOptions = { } ) {
1818 super ( scope , id ) ;
1919 this . options = options ;
2020
21- this . content =
22- options . content instanceof MediaType
23- ? options . content
24- : new MediaType ( this , `${ id } MediaType` , options . content ) ;
21+ if ( options . content ) {
22+ this . content =
23+ options . content instanceof MediaType
24+ ? options . content
25+ : new MediaType ( this , `${ id } MediaType` , options . content ) ;
26+ }
2527 }
2628
2729 public synth ( ) : OpenAPIV3_1 . ResponseObject {
2830 return {
2931 description : this . options . description || '' ,
3032 content : {
31- [ this . options . content . contentType ] : this . content . synth ( ) ,
33+ ...( this . content && {
34+ [ this . content . contentType ] : this . content . synth ( ) ,
35+ } ) ,
3236 } ,
3337 } ;
3438 }
You can’t perform that action at this time.
0 commit comments