#Swagger started throwing circular dependency errors where not before.

5 messages · Page 1 of 1 (latest)

waxen marsh
#

Hey all, I have an NX workspace project that I'm extensively implementing NestJS microservices. Inside some applications have both HTTP and TCP endpoints and some with just TCP. the one's with HTTP we document using the @nestjs/swagger library, and I'm currently getting an error at runtime with a circular dependency issue from at least two services that have HTTP endpoints. The error output is cryptic at best, but looking for the properties referenced, it doesn't seem to be an actual circular dependency. (unless I'm missing something completely.

For one (the main one I want to be worried about), the error is this:

 [Nest] 1  - 02/02/2024, 3:01:13 PM     LOG [InstanceLoader] ClientModule dependencies initialized +3ms
d-gateway  | [Nest] 1  - 02/02/2024, 3:01:13 PM     LOG [InstanceLoader] AppModule dependencies initialized +3ms
d-gateway  | [Nest] 1  - 02/02/2024, 3:01:13 PM     LOG [InstanceLoader] AuthModule dependencies initialized +0ms
d-gateway  | /app/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:187
d-gateway  |             throw new Error(`A circular dependency has been detected (property key: "${key}"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").`);
d-gateway  |                   ^
d-gateway  |
d-gateway  | Error: A circular dependency has been detected (property key: "startDate"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
d-gateway  |     at SchemaObjectFactory.createNotBuiltInTypeReference (/app/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:187:19)
d-gateway  |     at SchemaObjectFactory.createSchemaMetadata (/app/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:297:25)
d-gateway  |     at SchemaObjectFactory.mergePropertyWithMetadata (/app/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:131:21)
d-gateway  |     at /app/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:82:35
d-gateway  |     at Array.map (<anonymous>)
d-gateway  |     at SchemaObjectFactory.extractPropertiesFromType (/app/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:81:52)
d-gateway  |     at SchemaObjectFactory.exploreModelSchema (/app/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:103:41)
d-gateway  |     at /app/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:36:36
d-gateway  |     at Array.map (<anonymous>)
d-gateway  |     at SchemaObjectFactory.createFromModel (/app/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:20:45)
d-gateway  |
d-gateway  | Node.js v18.19.0
d-gateway exited with code 1

I can't find the key property, but the startDate key is on a route request body. and has no other dependencies other than the @ApiProperty() decorator. I'm lost AF.
I will gladly provide any additional, sanitized details we need to get this sorted.
here's the class that has the offensive dependency from my investigation as well.

import { ApiProperty } from "@nestjs/swagger";

export default class DateRange {
    @ApiProperty({ type: () => Date })
    startDate: Date;
    @ApiProperty({ type: () => Date })
    endDate: Date;
}
#

the resolver function pattern is from going off the error message.

#

I experienced the same issue on another branch, and when commenting out the swagger setup boilerplate, it no longer resolved my request body....

#

I would ask over on the NX discord, but it seems to be purely Nestjs/swagger's fault at this moment.

waxen marsh
#

some of it may be inter-project dependencies, I resolved 2 separate issues by moving them to a different lib from my workspace. I think I have where it's all coming from. I didn't follow the NX ethos close enough 😅