Skip to content

Commit

Permalink
feat: add initial swagger docs (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
CondensedMilk7 authored Sep 2, 2023
1 parent cc53c0b commit ba54833
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 3 deletions.
41 changes: 38 additions & 3 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@nestjs/mongoose": "^10.0.1",
"@nestjs/passport": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.1.10",
"bcrypt": "^5.1.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
Expand Down
2 changes: 2 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { ExceptionService } from './shared';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('root')
@Controller()
export class AppController {
constructor(
Expand Down
11 changes: 11 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { HttpExceptionsFilter } from './http-exceptions.filter';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import * as cookieParser from 'cookie-parser';

async function bootstrap() {
Expand All @@ -14,6 +15,16 @@ async function bootstrap() {
);
app.use(cookieParser());
app.useGlobalFilters(new HttpExceptionsFilter());

const config = new DocumentBuilder()
.setTitle('EverREST')
.setDescription('EverREST API description')
.setVersion('0.0.0')
.build();
const document = SwaggerModule.createDocument(app, config);
// TODO: Add swagger 'ApiProperty' to DTOs
SwaggerModule.setup('docs/swagger', app, document);

await app.listen(process.env.PORT || 3000);
}
bootstrap();
3 changes: 3 additions & 0 deletions src/modules/shop/cart/carts.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { CartsService } from './carts.service';
import { CurrentUser, CurrentUserInterceptor, JwtGuard } from 'src/shared';
import { UserPayload } from 'src/interfaces';
import { AddProductToCartDto, ProductIdDto } from '../dtos';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('cart')
@Controller('shop/cart')
@UseGuards(JwtGuard)
@UseInterceptors(CurrentUserInterceptor)
Expand Down
2 changes: 2 additions & 0 deletions src/modules/shop/product/products.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import {
import { CurrentUser, CurrentUserInterceptor, JwtGuard } from 'src/shared';
import { UserPayload } from 'src/interfaces';
import { MongooseValidatorService } from 'src/shared/mongoose-validator.service';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('products')
@Controller('shop/products')
export class ProductsController {
constructor(
Expand Down
2 changes: 2 additions & 0 deletions src/modules/user/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import { LocalAuthGuard, RefreshJwtGuard } from './guards';
import { Response } from 'express';
import { CurrentUser, CurrentUserInterceptor, JwtGuard } from 'src/shared';
import { UserPayload } from 'src/interfaces';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('auth')
@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}
Expand Down

0 comments on commit ba54833

Please sign in to comment.