Resolving Circular Dependency Issue between NestJS Swagger and class-validator within Docker Container

82 views Asked by At

I'm encountering a circular dependency issue within a NestJS application when utilizing Swagger for API documentation and class-validator for input validation. Interestingly, this issue only manifests when the application is executed within a Docker container; running it outside of Docker does not reproduce the problem.

The NestJS application employs the UploadFileRequest,CreateFileRequest class, which defines properties decorated with @ApiProperty from Swagger and @IsNotEmpty from class-validator. Despite adhering to best practices and ensuring that the codebase has no direct circular dependencies, the issue persists exclusively within the Docker environment.

export class UploadFileRequest {

@ApiProperty({ description: 'fileCategory' })
@IsNotEmpty({ message: 'fileCategory must not be null' })
fileCategory: FileCategory;

// Other properties...
}


export class CreateFileRequest {

@ApiProperty({ description: 'fileCategory' })
@IsNotEmpty({ message: 'fileCategory must not be null' })
fileCategory: FileCategory;

// Other properties...
}

I got this error

Question: Why might this circular dependency issue occur only when running the NestJS application inside a Docker container, and how can I resolve it?

Any insights or suggestions would be greatly appreciated. Thank you!

0

There are 0 answers