Skip to content

Commit cde888e

Browse files
committed
feat: support for empty content type in response (ie void response)
1 parent e668cec commit cde888e

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

lib/request-body.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,35 @@ import type { OpenAPIV3_1 } from 'openapi-types';
33
import { MediaType, type MediaTypeOptions } from './media-type.js';
44

55
export interface RequestBodyOptions {
6-
content: MediaType | MediaTypeOptions;
6+
content?: MediaType | MediaTypeOptions;
77
description?: string;
88
required?: boolean;
99
}
1010

1111
export class RequestBody extends Construct {
1212
private options: RequestBodyOptions;
1313

14-
private content: MediaType;
14+
private content: MediaType | undefined;
1515

1616
constructor(scope: Construct, id: string, options: RequestBodyOptions) {
1717
super(scope, id);
1818
this.options = options;
1919

20-
this.content =
21-
options.content instanceof MediaType
22-
? options.content
23-
: new MediaType(this, id, options.content);
20+
if (options.content) {
21+
this.content =
22+
options.content instanceof MediaType
23+
? options.content
24+
: new MediaType(this, id, options.content);
25+
}
2426
}
2527

2628
public synth(): OpenAPIV3_1.RequestBodyObject {
2729
return {
2830
description: this.options.description || '',
2931
content: {
30-
[this.options.content.contentType]: this.content.synth(),
32+
...(this.content && {
33+
[this.content.contentType]: this.content.synth(),
34+
}),
3135
},
3236
...(this.options.required && { required: this.options.required }),
3337
};

0 commit comments

Comments
 (0)