Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(swagger): fix the parsing of enum types with array (#4078) #4098

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这好像不是这么用的

{
    type: 'array',
    items: {
      type: 'enum',
      enum: Animal
    },
  }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实,我一会改一下看看

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像有那么点道理。。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

单测写的有点问题,我这边改了一下

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原来我一开始理解对了 🤣
但我后面细看了下你引用的代码块,以为你在说单测的问题,单测也确实有问题

type: 'enum',
isArray: true,
enum: [0, 1, 2],
});
})
});

describe('test @ApiOperation', () => {
Expand Down
Loading