Skip to content

Commit

Permalink
Docs: API 문서 포맷 변경
Browse files Browse the repository at this point in the history
- 패키지 설치
- Swagger 문서를 Scalar 문서로 변경
- main.ts에 Scalar 설정 추가
- /api prefix 제거
- setGlobalPrefix 제외
- 문서 url path를 api/swagger -> /reference로 변경

Related to #20
  • Loading branch information
Zamoca42 committed Jan 27, 2024
1 parent bbe3404 commit d1055a4
Show file tree
Hide file tree
Showing 4 changed files with 3,571 additions and 194 deletions.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.1.14",
"@scalar/nestjs-api-reference": "^0.1.28",
"@supabase/supabase-js": "^2.39.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
Expand Down
1 change: 0 additions & 1 deletion backend/src/common/config/swagger.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { DocumentBuilder, OpenAPIObject } from '@nestjs/swagger';

export const swaggerConfig: Omit<OpenAPIObject, 'paths'> = new DocumentBuilder()
.setTitle('Do-It Toeic API Document')
.addServer('/api')
.addBearerAuth(
{
type: 'http',
Expand Down
11 changes: 9 additions & 2 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ import { useContainer } from 'class-validator';
import { swaggerConfig } from './common/config/swagger.config';
import { pipeOptions } from './common/config/pipe.config';
import { corsOptions } from './common/config/cors.config';
import { apiReference } from '@scalar/nestjs-api-reference';
import * as cookieParser from 'cookie-parser';

async function bootstrap(): Promise<void> {
const app = await NestFactory.create(AppModule, {
bufferLogs: true,
});
const document = SwaggerModule.createDocument(app, swaggerConfig);
SwaggerModule.setup('/api/swagger', app, document);

app.setGlobalPrefix('api');
app.use(
'/reference',
apiReference({
spec: {
content: document,
},
}),
);
app.use(cookieParser());
app.enableCors(corsOptions);
app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));
Expand Down
Loading

0 comments on commit d1055a4

Please sign in to comment.