@nest/swagger comments in nested objects doesn't work

206 views Asked by At

I created a NestJs project and added @nestjs/swagger as a plugin (with introspectComments enabled)

Now Swagger works well and I can see the docs work as expected, except for nested objects and array of objects

// 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
}
1

There are 1 answers

0
Sherif eldeeb On BEST ANSWER

solution the issue is solved by switching from TS interfaces into js classes so, instead of

export interface Item{...}

use

export class Item{...}