嵌套对象中的@nest/swagger注解无效

0ejtzxu1  于 7个月前  发布在  其他
关注(0)|答案(1)|浏览(124)

我创建了一个NestJs项目,并添加了@nestjs/swagger作为插件(启用了introspectComments
现在Swagger工作得很好,我可以看到文档像预期的那样工作,除了嵌套对象和对象数组

// users/dto/create-user.dto.ts
import { CurrencyCode } from './currencies';

export class CreateCheckoutDto {
  //This works well and I can see the example correctly in Swagger's docs
  /**
   * @example john
   */
  name: string;

  // but this object appears empty as '{}'
  // without its props
  items: Item[];

  // This causes an error
  // A circular dependency has been detected (property key: "items2"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
}
  items2: [{ test: string; }]

export interface Item {
  /**
   * @example anything
   */
  test: string
}

字符串

ar7v8xwq

ar7v8xwq1#

解决方案这个问题是通过从TS接口切换到js类来解决的,所以,

export interface Item{...}

字符串
使用

export class Item{...}

相关问题