Skip to content

Commit 2a98d16

Browse files
authored
Swagger docs updated (#234)
* Swagger docs updated * fix * Update test-variations.service.ts * Update test-runs.e2e-spec.ts * Update create-test-request-multipart.dto.ts
1 parent 467c949 commit 2a98d16

20 files changed

+175
-49
lines changed

src/builds/builds.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class BuildsController {
5858
}
5959

6060
@Delete(':id')
61+
@ApiOkResponse({ type: BuildDto })
6162
@ApiBearerAuth()
6263
@UseGuards(JwtAuthGuard, RoleGuard)
6364
@Roles(Role.admin, Role.editor)

src/builds/dto/build-paginated.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { Pagination } from '../../shared/dto/pagination.dto';
33
import { BuildDto } from './build.dto';
44

55
export class PaginatedBuildDto extends Pagination {
6-
@ApiProperty({ type: [BuildDto] })
6+
@ApiProperty({ type: BuildDto, isArray: true })
77
data: BuildDto[];
88
}

src/health/health.controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Controller, Get } from '@nestjs/common';
22
import { HealthCheckService, HealthCheck } from '@nestjs/terminus';
33
import { PrismaService } from '../prisma/prisma.service';
4+
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
45

6+
@ApiTags('health')
57
@Controller('health')
68
export class HealthController {
79
constructor(
@@ -10,6 +12,7 @@ export class HealthController {
1012
) {}
1113

1214
@Get()
15+
@ApiOkResponse({type: Object})
1316
@HealthCheck()
1417
check() {
1518
return this.health.check([() => this.prismaService.$queryRaw`SELECT 1`]);

src/projects/dto/project.dto.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ApiProperty } from '@nestjs/swagger';
2-
import { IsUUID, IsString, IsNumber, IsBoolean, IsEnum, IsJSON } from 'class-validator';
2+
import { IsUUID, IsString, IsNumber, IsBoolean, IsEnum, IsJSON, IsDate } from 'class-validator';
33
import { ImageComparison, Project } from '@prisma/client';
4+
import { Type } from 'class-transformer';
45

56
export class ProjectDto implements Project {
67
@ApiProperty()
@@ -20,9 +21,13 @@ export class ProjectDto implements Project {
2021
readonly mainBranchName: string;
2122

2223
@ApiProperty()
24+
@IsDate()
25+
@Type(() => Date)
2326
readonly createdAt: Date;
2427

2528
@ApiProperty()
29+
@IsDate()
30+
@Type(() => Date)
2631
readonly updatedAt: Date;
2732

2833
@ApiProperty()

src/projects/projects.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ProjectsController {
1717
@Get()
1818
@ApiBearerAuth()
1919
@UseGuards(JwtAuthGuard)
20-
@ApiOkResponse({ type: [ProjectDto] })
20+
@ApiOkResponse({ type: ProjectDto, isArray: true })
2121
getAll(): Promise<Project[]> {
2222
return this.projectsService.findAll();
2323
}

src/shared/dto/baseline.dto.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { TestRunDto } from '../../test-runs/dto/testRun.dto';
3+
import { UserDto } from '../../users/dto/user.dto';
4+
5+
export class BaselineDto {
6+
@ApiProperty()
7+
id: string;
8+
9+
@ApiProperty()
10+
baselineName: string;
11+
12+
@ApiProperty()
13+
testVariationId: string;
14+
15+
@ApiProperty()
16+
createdAt: Date;
17+
18+
@ApiProperty()
19+
updatedAt: Date;
20+
21+
@ApiProperty()
22+
testRun: TestRunDto;
23+
24+
@ApiProperty()
25+
user: UserDto;
26+
}
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1+
import { ApiPropertyOptional, OmitType } from '@nestjs/swagger';
12
import { ApiFile } from '../../shared/api-file.decorator';
23
import { CreateTestRequestDto } from './create-test-request.dto';
4+
import { Transform, Type } from 'class-transformer';
5+
import { IgnoreAreaDto } from './ignore-area.dto';
6+
import { IsBoolean, IsNumber, IsOptional } from 'class-validator';
37

4-
export class CreateTestRequestMultipartDto extends CreateTestRequestDto {
8+
export class CreateTestRequestMultipartDto extends OmitType(CreateTestRequestDto, [
9+
'ignoreAreas',
10+
'merge',
11+
'diffTollerancePercent',
12+
]) {
513
@ApiFile()
614
image: Express.Multer.File;
15+
16+
@ApiPropertyOptional()
17+
@IsOptional()
18+
@IsNumber()
19+
@Transform(({ value }) => parseFloat(value) || 0)
20+
diffTollerancePercent?: number;
21+
22+
@ApiPropertyOptional()
23+
@IsOptional()
24+
@IsBoolean()
25+
@Transform(({ value }) => value == 'true')
26+
merge?: boolean;
27+
28+
@ApiPropertyOptional({ type: String })
29+
@IsOptional()
30+
@Type(() => String)
31+
@Transform(({ value }) => (value ? JSON.parse(value) : []))
32+
ignoreAreas?: IgnoreAreaDto[];
733
}

src/test-runs/dto/create-test-request.dto.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
2-
import { Transform } from 'class-transformer';
3-
import { IsOptional, IsUUID, IsNumber, IsBoolean, IsString } from 'class-validator';
4-
import { isArray } from 'lodash';
2+
import { Type } from 'class-transformer';
3+
import { IsOptional, IsUUID, IsNumber, IsBoolean, IsString, IsArray, ValidateNested } from 'class-validator';
54
import { BaselineDataDto } from '../../shared/dto/baseline-data.dto';
65
import { IgnoreAreaDto } from './ignore-area.dto';
76

@@ -17,32 +16,18 @@ export class CreateTestRequestDto extends BaselineDataDto {
1716
@ApiPropertyOptional()
1817
@IsOptional()
1918
@IsNumber()
20-
@Transform(({ value }) => parseFloat(value))
2119
diffTollerancePercent?: number;
2220

2321
@ApiPropertyOptional()
2422
@IsBoolean()
2523
@IsOptional()
26-
@Transform(({ value }) => {
27-
switch (value) {
28-
case 'true':
29-
return true;
30-
case 'false':
31-
return false;
32-
default:
33-
return value;
34-
}
35-
})
3624
merge?: boolean;
3725

38-
@ApiPropertyOptional({ type: [IgnoreAreaDto] })
26+
@ApiPropertyOptional({ type: IgnoreAreaDto, isArray: true })
3927
@IsOptional()
40-
@Transform(({ value }) => {
41-
if (isArray(value)) {
42-
return value;
43-
}
44-
return JSON.parse(value);
45-
})
28+
@IsArray()
29+
@Type(() => IgnoreAreaDto)
30+
@ValidateNested({ each: true })
4631
ignoreAreas?: IgnoreAreaDto[];
4732

4833
@ApiPropertyOptional()

src/test-runs/dto/testRun-paginated.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { Pagination } from '../../shared/dto/pagination.dto';
33
import { TestRunDto } from './testRun.dto';
44

55
export class PaginatedTestRunDto extends Pagination {
6-
@ApiProperty({ type: [TestRunDto] })
6+
@ApiProperty({ type: TestRunDto, isArray: true })
77
data: TestRunDto[];
88
}

src/test-runs/dto/testRun.dto.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApiProperty } from '@nestjs/swagger';
1+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
22
import { TestRun, TestStatus } from '@prisma/client';
33

44
export class TestRunDto {
@@ -36,7 +36,7 @@ export class TestRunDto {
3636
ignoreAreas: string;
3737
@ApiProperty()
3838
tempIgnoreAreas: string;
39-
@ApiProperty()
39+
@ApiPropertyOptional()
4040
comment?: string;
4141
@ApiProperty()
4242
branchName: string;

0 commit comments

Comments
 (0)