Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧩 [Task]: NestJS 框架引入自动生成 API 文档依赖用于自动生成API文档 #11

Open
3 tasks done
T8840 opened this issue May 6, 2023 · 0 comments
Open
3 tasks done
Assignees
Labels
effort:3 估计需要 3 小时可以完成 state:approved 已经被同意/允许并入分支 type:task 有具体交付结果的任务

Comments

@T8840
Copy link
Collaborator

T8840 commented May 6, 2023

任务内容 Task Details

  1. 安装所需的依赖项:npm install @nestjs/swagger swagger-ui-express
  2. 在 main.ts 文件中,配置并启用 SwaggerModule:

`import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);

// Configure Swagger
const config = new DocumentBuilder()
.setTitle('My API')
.setDescription('The API description')
.setVersion('1.0')
.addTag('my-tag')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);

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

4.在应用程序中,使用装饰器为 API 端点添加文档信息。这些装饰器包括 @ApiTags, @ApiOperation, @ApiParam, @ApiBody, @apiquery, @ApiResponse 等。这些装饰器可以在控制器和实体类中使用,以提供有关 API 的详细信息。
`import {
Controller,
Get,
Param,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiParam } from '@nestjs/swagger';

@ApiTags('users')
@controller('users')
export class UsersController {
@get(':id')
@ApiOperation({ summary: 'Get user by ID' })
@ApiParam({ name: 'id', description: 'User ID' })
findOne(@param('id') id: string): string {
return User with ID ${id};
}
}`

交付物 (选填) Deliverables

  1. NestJS会显示Swagger 的信息

截止期限 (选填) Deadline (optional)

No response

检查清单 Checklist:

  • 我已经在右侧选择 effort 标签,标注估计工作量 I have selected the effort label on the right side to estimate the work done.
  • 如果需求相对急迫 (2 周内),请在右侧选择 priority 标签 For urgent requests (within 2 weeks), please select the priority label on the right.
  • 我了解没有依照格式提交需求清单,将会被关闭 I understand that improperly formatted product backlog may be closed without explanation.
@T8840 T8840 added effort:5 估计需要 5 小时可以完成 state:pending 尚待决定是否需要解决/并入分支 type:task 有具体交付结果的任务 labels May 6, 2023
@T8840 T8840 self-assigned this May 9, 2023
@T8840 T8840 added state:approved 已经被同意/允许并入分支 effort:3 估计需要 3 小时可以完成 and removed state:pending 尚待决定是否需要解决/并入分支 effort:5 估计需要 5 小时可以完成 labels May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort:3 估计需要 3 小时可以完成 state:approved 已经被同意/允许并入分支 type:task 有具体交付结果的任务
Projects
None yet
Development

No branches or pull requests

1 participant