Круговая зависимость с гнездом js Swagger 4 - PullRequest
0 голосов
/ 19 марта 2020

Когда я обновил библиотеку @ nest / swagger до версии 4, произошла эта ошибка:

(node:16134) UnhandledPromiseRejectionWarning: Error: A circular dependency has been detected (property key: "customer"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
    at SchemaObjectFactory.createNotBuiltInTypeReference (/opt/desenvolvimento/Haizen/projectx_back/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:182:19)
    at SchemaObjectFactory.mergePropertyWithMetadata (/opt/desenvolvimento/Haizen/projectx_back/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:117:25)
    at /opt/desenvolvimento/Haizen/projectx_back/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:66:35
    at Array.map (<anonymous>)
    at SchemaObjectFactory.exploreModelSchema (/opt/desenvolvimento/Haizen/projectx_back/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:65:52)
    at SchemaObjectFactory.createNotBuiltInTypeReference (/opt/desenvolvimento/Haizen/projectx_back/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:187:37)
    at SchemaObjectFactory.mergePropertyWithMetadata (/opt/desenvolvimento/Haizen/projectx_back/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:117:25)
    at /opt/desenvolvimento/Haizen/projectx_back/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:66:35
    at Array.map (<anonymous>)
    at SchemaObjectFactory.exploreModelSchema (/opt/desenvolvimento/Haizen/projectx_back/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:65:52)

Класс моей модели выглядит так:

@Entity()
export class Job {
.
.
.
    @ManyToOne(type => Customer, customer => customer.jobs)
    @ApiProperty({ type: Customer })
    customer: Customer;
}

1 Ответ

1 голос
/ 19 марта 2020

Решение, которое работало для меня, состояло в том, чтобы объявить в @ ApiProperty () тип с функцией стрелки , как показано ниже:

@Entity()
export class Job {
.
.
.
    @ManyToOne(type => Customer, customer => customer.jobs)
    @ApiProperty({ type: () => Customer })
    customer: Customer;
}
...