diff --git a/packages/swagger/src/decorators/api-property.decorator.ts b/packages/swagger/src/decorators/api-property.decorator.ts index 4dce026e5be..2808f14f312 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/__snapshots__/parser.test.ts.snap b/packages/swagger/test/__snapshots__/parser.test.ts.snap index 7cb4676488d..9361c7148c2 100644 --- a/packages/swagger/test/__snapshots__/parser.test.ts.snap +++ b/packages/swagger/test/__snapshots__/parser.test.ts.snap @@ -1350,6 +1350,26 @@ exports[`test @ApiParam should test with @Param decorator 1`] = ` } `; +exports[`test @ApiProperty should format enum type with array 1`] = ` +{ + "properties": { + "animal": { + "isArray": true, + "items": { + "enum": [ + 0, + 1, + 2, + ], + "type": "number", + }, + "type": "array", + }, + }, + "type": "object", +} +`; + exports[`test @ApiProperty should parse base type 1`] = ` { "properties": { diff --git a/packages/swagger/test/parser.test.ts b/packages/swagger/test/parser.test.ts index 1c81acbe1a9..89d034d29e4 100644 --- a/packages/swagger/test/parser.test.ts +++ b/packages/swagger/test/parser.test.ts @@ -1776,6 +1776,44 @@ describe('test @ApiProperty', () => { const explorer = new CustomSwaggerExplorer(); expect(explorer.parse(Cat)).toMatchSnapshot(); }); + + it('should format enum type with array', () => { + enum Animal { + Cat = 0, + Dog = 1, + Pig = 2, + } + + class Dto { + @ApiProperty({ + type: 'enum', + enum: Animal, + isArray: true, + }) + animal: Animal[]; + } + + const explorer = new CustomSwaggerExplorer(); + const result = explorer.parse(Dto) + // expect(explorer.parse(Dto)).toMatchSnapshot(); + expect(result).toEqual({ + properties: { + animal: { + isArray: true, + items: { + enum: [ + 0, + 1, + 2, + ], + type: 'number', + }, + type: 'array', + }, + }, + type: 'object', + }) + }) }); describe('test property metadata parse', () => {