Skip to content

Commit

Permalink
swagger-ui added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmet AYDIN committed Feb 9, 2020
1 parent d382c68 commit 16c476a
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 1 deletion.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@nestjs/core": "^6.7.2",
"@nestjs/mongoose": "^6.2.1",
"@nestjs/platform-express": "^6.7.2",
"@nestjs/swagger": "^4.2.6",
"bcrypt": "^3.0.7",
"class-transformer": "^0.2.3",
"class-validator": "^0.11.0",
Expand All @@ -32,7 +33,8 @@
"mongoose": "^5.8.9",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.0",
"rxjs": "^6.5.3"
"rxjs": "^6.5.3",
"swagger-ui-express": "^4.1.3"
},
"devDependencies": {
"@nestjs/cli": "^6.9.0",
Expand Down
11 changes: 11 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ import { NestFactory, HttpAdapterHost } from '@nestjs/core';
import { AppModule } from './app.module';
import { AllExceptionFilter } from 'libs/filters/all-exception.filter';
import { ValidationPipe } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const { httpAdapter } = app.get(HttpAdapterHost);
app.useGlobalFilters(new AllExceptionFilter(httpAdapter));
app.setGlobalPrefix('api');
app.useGlobalPipes(new ValidationPipe());

const options = new DocumentBuilder()
.setTitle('Udemy course API endpoints')
.setDescription('These are all udemy nestjs course api endpoints.')
.setVersion('1.0')
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api', app, document);

await app.listen(3000);
}
bootstrap();
2 changes: 2 additions & 0 deletions src/ticket/ticket-type/ticket-type.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
import { TicketTypeService } from './ticket-type.service';
import { TicketTypeModel } from 'tools/models/ticket-type.model';
import { TicketTypeDto } from 'tools/dtos/ticket-type.dto';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('ticket-type')
@Controller('ticket-type')
export class TicketTypeController {
constructor(private readonly ticketTypeService: TicketTypeService) {}
Expand Down
2 changes: 2 additions & 0 deletions src/ticket/ticket.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
import { TicketService } from './ticket.service';
import { TicketModel } from 'tools/models/ticket.model';
import { TicketCreateDto } from 'tools/dtos/ticket.dto';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('ticket')
@Controller('ticket')
export class TicketController {
constructor(private readonly ticketService: TicketService) {}
Expand Down
2 changes: 2 additions & 0 deletions src/total/total.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Controller, Get } from '@nestjs/common';
import { UserModel } from 'tools/models/user.model';
import { TotalService } from './total.service';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('total')
@Controller('total')
export class TotalController {
constructor(private totalService: TotalService) {}
Expand Down
2 changes: 2 additions & 0 deletions src/upload/upload.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { UploadService } from './upload.service';
import { FilesInterceptor } from '@nestjs/platform-express';
import { extname } from 'path';
import { diskStorage } from 'multer';
import { ApiTags } from '@nestjs/swagger';

const storageOptions = diskStorage({
destinaton: './uploads',
Expand All @@ -16,6 +17,7 @@ const storageOptions = diskStorage({
},
});

@ApiTags('upload')
@Controller('upload')
export class UploadController {
constructor(private readonly uploadService: UploadService) {}
Expand Down
3 changes: 3 additions & 0 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import { UserCreateDto, UserUpdateDto } from 'tools/dtos/user.dto';
import { UserModel } from 'tools/models/user.model';
import { FilterModel } from 'tools/models/filter.model';
import { Roles } from 'libs/decorators/role.decorator';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';

@ApiBearerAuth()
@ApiTags('user')
@Controller('user')
export class UserController {
constructor(private userService: UserService) {}
Expand Down
15 changes: 15 additions & 0 deletions tools/dtos/user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
import { RoleModel } from 'tools/models/role.model';
import { GroupModel } from 'tools/models/group.model';
import { IsNotEmpty, Length, IsEmail, IsDateString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class UserCreateDto {
@IsNotEmpty()
@Length(2, 20)
@ApiProperty()
name: string;
@ApiProperty()
surname: string;
@ApiProperty()
image: string;
@ApiProperty()
password: string;
@ApiProperty()
@IsEmail()
email: string;
@ApiProperty()
@IsDateString()
birthDay: Date;
}

// tslint:disable-next-line:max-classes-per-file
export class UserUpdateDto {
@ApiProperty()
name: string;
@ApiProperty()
surname: string;
@ApiProperty()
image: string;
@ApiProperty()
password: string;
@ApiProperty()
email: string;
@ApiProperty()
birthDay: Date;
roles: RoleModel[];
groups: GroupModel[];
}

// tslint:disable-next-line:max-classes-per-file
export class UserLoginDto {
@ApiProperty()
email: string;
@ApiProperty()
password: string;
}

0 comments on commit 16c476a

Please sign in to comment.