From dc2a74dc40aeace48c5ff4edf443ea999f832de7 Mon Sep 17 00:00:00 2001 From: kelvin Date: Sun, 29 Sep 2024 16:01:07 +0800 Subject: [PATCH] fix(swagger): fix the parsing of enum types with array (#4083) --- .../src/decorators/api-property.decorator.ts | 2 +- packages/swagger/test/parser.test.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/swagger/src/decorators/api-property.decorator.ts b/packages/swagger/src/decorators/api-property.decorator.ts index 4dce026e5be3..2808f14f3122 100644 --- a/packages/swagger/src/decorators/api-property.decorator.ts +++ b/packages/swagger/src/decorators/api-property.decorator.ts @@ -45,7 +45,7 @@ export function createApiPropertyDecorator( options.type = getEnumType(enumValues); } - if (isArray) { + if (options.type !== 'array' && isArray) { options.type = 'array'; options.items = { type: type as any, diff --git a/packages/swagger/test/parser.test.ts b/packages/swagger/test/parser.test.ts index 1c81acbe1a99..25f2822cc23c 100644 --- a/packages/swagger/test/parser.test.ts +++ b/packages/swagger/test/parser.test.ts @@ -2208,6 +2208,26 @@ describe('test property metadata parse', () => { additionalProperties: true }); }); + + it('should format enum type with array', () => { + enum Animal { + Cat = 0, + Dog = 1, + Pig = 2, + } + + const result = swaggerExplorer.formatType({ + type: 'enum', + enum: Animal, + isArray: true, + }); + + expect(result).toEqual({ + type: 'enum', + isArray: true, + enum: [0, 1, 2], + }); + }) }); describe('test @ApiOperation', () => {