File tree Expand file tree Collapse file tree 3 files changed +101
-5
lines changed Expand file tree Collapse file tree 3 files changed +101
-5
lines changed Original file line number Diff line number Diff line change @@ -438,7 +438,7 @@ export class SwaggerExplorer {
438
438
param . metadata . schema [ 'type' ] = param . metadata . type ;
439
439
delete param . metadata . type ;
440
440
}
441
- if ( param . metadata . isArray !== undefined ) {
441
+ if ( param . metadata . isArray ) {
442
442
param . metadata . schema [ 'items' ] = {
443
443
type : param . metadata . schema [ 'type' ] ,
444
444
} ;
Original file line number Diff line number Diff line change @@ -165,10 +165,7 @@ exports[`test @ApiBody should test ApiBody 1`] = `
165
165
" content" : {
166
166
" application/json" : {
167
167
" schema" : {
168
- " items" : {
169
- " $ref" : " #/components/schemas/Cat" ,
170
- },
171
- " type" : " array" ,
168
+ " $ref" : " #/components/schemas/Cat" ,
172
169
},
173
170
},
174
171
},
@@ -269,6 +266,74 @@ exports[`test @ApiBody should test ApiBody with array 1`] = `
269
266
}
270
267
` ;
271
268
269
+ exports [` test @ApiBody should test ApiBody with array false 1` ] = `
270
+ {
271
+ " components" : {
272
+ " schemas" : {
273
+ " Cat" : {
274
+ " properties" : {
275
+ " age" : {
276
+ " description" : " The age of the Cat" ,
277
+ " example" : 1 ,
278
+ " type" : " number" ,
279
+ },
280
+ " name" : {
281
+ " description" : " The name of the Cat" ,
282
+ " example" : " Kitty" ,
283
+ " type" : " string" ,
284
+ },
285
+ },
286
+ " type" : " object" ,
287
+ },
288
+ },
289
+ },
290
+ " info" : {
291
+ " contact" : {},
292
+ " description" : " " ,
293
+ " title" : " " ,
294
+ " version" : " 1.0.0" ,
295
+ },
296
+ " openapi" : " 3.0.1" ,
297
+ " paths" : {
298
+ " /api/update_user" : {
299
+ " post" : {
300
+ " description" : undefined ,
301
+ " operationId" : " apicontroller_updateuser" ,
302
+ " parameters" : [],
303
+ " requestBody" : {
304
+ " content" : {
305
+ " application/json" : {
306
+ " schema" : {
307
+ " $ref" : " #/components/schemas/Cat" ,
308
+ },
309
+ },
310
+ },
311
+ " description" : undefined ,
312
+ " required" : true ,
313
+ },
314
+ " responses" : {
315
+ " 200" : {
316
+ " description" : " OK" ,
317
+ },
318
+ },
319
+ " summary" : undefined ,
320
+ " tags" : [
321
+ " api" ,
322
+ ],
323
+ },
324
+ },
325
+ },
326
+ " servers" : [],
327
+ " tags" : [
328
+ {
329
+ " description" : " api" ,
330
+ " externalDocs" : undefined ,
331
+ " name" : " api" ,
332
+ },
333
+ ],
334
+ }
335
+ ` ;
336
+
272
337
exports [` test @ApiBody should test ApiBody with binary 1` ] = `
273
338
{
274
339
" components" : {},
Original file line number Diff line number Diff line change @@ -416,6 +416,37 @@ describe('test @ApiBody', () => {
416
416
expect ( explorer . getData ( ) ) . toMatchSnapshot ( ) ;
417
417
} ) ;
418
418
419
+ it ( 'should test ApiBody with array false' , ( ) => {
420
+ class Cat {
421
+ /**
422
+ * The name of the Catcomment
423
+ * @example Kitty
424
+ */
425
+ @ApiProperty ( { example : 'Kitty' , description : 'The name of the Cat' } )
426
+ name : string ;
427
+
428
+ @ApiProperty ( { example : 1 , description : 'The age of the Cat' } )
429
+ age : number ;
430
+ }
431
+
432
+ @Controller ( '/api' )
433
+ @ApiExtraModel ( Cat )
434
+ class APIController {
435
+ @Post ( '/update_user' )
436
+ @ApiBody ( {
437
+ type : Cat ,
438
+ isArray : false ,
439
+ } )
440
+ async updateUser ( @Body ( ) cat : Cat [ ] ) {
441
+ // ...
442
+ }
443
+ }
444
+
445
+ const explorer = new CustomSwaggerExplorer ( ) ;
446
+ explorer . generatePath ( APIController ) ;
447
+ expect ( explorer . getData ( ) ) . toMatchSnapshot ( ) ;
448
+ } ) ;
449
+
419
450
it ( 'should test ApiBody with example' , ( ) => {
420
451
class Cat {
421
452
@ApiProperty ( { example : 'Kitty' , description : 'The name of the Cat' } )
You can’t perform that action at this time.
0 commit comments