Skip to content

Commit

Permalink
feat: swagger로 api 문서화
Browse files Browse the repository at this point in the history
  • Loading branch information
publdaze committed Jul 20, 2023
1 parent 1f5fc54 commit 6088a6b
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 14 deletions.
10 changes: 9 additions & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
"deleteOutDir": true,
"plugins": [
{
"name": "@nestjs/swagger",
"options": {
"introspectComments": true
}
}
]
}
}
87 changes: 81 additions & 6 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 @@ -25,6 +25,7 @@
"@nestjs/core": "^10.0.0",
"@nestjs/mongoose": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.1.2",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"mongoose": "^7.3.4",
Expand Down
7 changes: 0 additions & 7 deletions src/buildings/dtos/create-building.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,4 @@ export class CreateBuildingDto {

@IsString()
readonly buildingName: string;

status: {
regular: number;
bottle: number;
plastic: number;
paper: number;
};
}
8 changes: 8 additions & 0 deletions src/buildings/floors/floors.controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { Body, Controller, Param, Post } from '@nestjs/common';
import { FloorsService } from './floors.service';
import { ApiBody } from '@nestjs/swagger';

@Controller()
export class FloorsController {
constructor(private readonly floorsService: FloorsService) {}

@ApiBody({
schema: {
properties: {
floorNumber: { type: 'number' },
},
},
})
@Post('/buildings/:buildingNumber/floors')
createFloor(
@Param('buildingNumber') buildingNumber: number,
Expand Down
8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
Expand All @@ -13,6 +14,13 @@ async function bootstrap() {
}),
);

const config = new DocumentBuilder()
.setTitle('Trashcan API')
.setDescription('쓰레기통 API 입니다.')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('docs', app, document);

await app.listen(3000);
}
bootstrap();

0 comments on commit 6088a6b

Please sign in to comment.