@@ -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 }
0 commit comments