Skip to content

Commit

Permalink
fix(swagger): fix the parsing of enum types with array (midwayjs#4083)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin committed Sep 29, 2024
1 parent eaa292a commit dc2a74d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/swagger/src/decorators/api-property.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions packages/swagger/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit dc2a74d

Please sign in to comment.