小编And*_*uma的帖子

如何在 Nx monorepo 中为 NestJS 和 Angular 之间共享的 API 接口启用 Swagger?

我想为 API 接口启用 Swagger,在 Nx monorepo 中的 NestJS 和 Angular 应用程序之间共享。是否有一致的而不是变通的方式?

这些是我没有成功的方法:

方法 1. 将@nestjs/swagger装饰器应用于共享 DTO 类

  • 创建一个新的 Nx monorepo npx create-nx-workspace@latest
  • 选择angular-nest工作区蓝图
  • 安装 Swagger 依赖项并根据指南引导它
  • 添加类型的输入Messageapp.component.ts(没有意义,只是为了测试):
export class AppComponent {
  @Input() message: Message;

  hello$ = this.http.get<Message>('/api/hello');
  constructor(private http: HttpClient) {}
}
Run Code Online (Sandbox Code Playgroud)
  • messageApiProperty()in装饰属性api-interfaces.ts
import { ApiProperty } from '@nestjs/swagger';

export class Message {
  @ApiProperty()
  message: string;
}
Run Code Online (Sandbox Code Playgroud)
  • 运行 NestJS 应用程序。它工作正常,Swagger 在 Web 视图中显示正确的 DTO 结构 …

swagger angular nestjs nrwl-nx

7
推荐指数
1
解决办法
2679
查看次数

标签 统计

angular ×1

nestjs ×1

nrwl-nx ×1

swagger ×1