File tree 2 files changed +13
-0
lines changed
2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,7 @@ export const registerSchemaPath = ({
264
264
...( bodySchema
265
265
? {
266
266
requestBody : {
267
+ required : true ,
267
268
content : mapTypesResponse (
268
269
contentTypes ,
269
270
typeof bodySchema === 'string'
Original file line number Diff line number Diff line change @@ -156,4 +156,16 @@ describe('Swagger', () => {
156
156
response . paths [ '/null' ] . get . responses [ '204' ] . content
157
157
) . toBeUndefined ( )
158
158
} )
159
+
160
+ it ( "should set the required field to true when a request body is present" , async ( ) => {
161
+ const app = new Elysia ( ) . use ( swagger ( ) ) . post ( "/post" , ( ) => { } , {
162
+ body : t . Object ( { name : t . String ( ) } ) ,
163
+ } ) ;
164
+
165
+ const res = await app . handle ( req ( "/swagger/json" ) ) ;
166
+ expect ( res . status ) . toBe ( 200 ) ;
167
+ const response = await res . json ( ) ;
168
+ expect ( response . paths [ '/post' ] . post . requestBody . required ) . toBe ( true ) ;
169
+ } )
170
+
159
171
} )
You can’t perform that action at this time.
0 commit comments