Skip to content

Commit

Permalink
fix(swagger): test
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin committed Sep 29, 2024
1 parent 8c9661a commit ed29679
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
20 changes: 20 additions & 0 deletions packages/swagger/test/__snapshots__/parser.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
40 changes: 20 additions & 20 deletions packages/swagger/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,26 @@ 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();
expect(explorer.parse(Dto)).toMatchSnapshot();
})
});

describe('test property metadata parse', () => {
Expand Down Expand Up @@ -2208,26 +2228,6 @@ 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 ed29679

Please sign in to comment.