#Manually starting NestJS api with plugins

24 messages · Page 1 of 1 (latest)

past lance
#

Hey. I want to start an API server with Swagger documentation but in runtime as a part of a bot.
The issue is that swagger does not want to infer class-validator decorator's types in my DTOs.
How can I start nestjs in runtime with the full functionality of the @nestjs/cli?

Error appended as a file because I guess it is too big for discord

vivid marsh
#

it's a circular dependency

#

are you using forwared ref or inject in the service?

past lance
#

I mean if I manually specify the type in swagger @ApiProperty decorator everything works fine

#

I'm 99% sure there are no circular deps because if I manually specify the types in the DTOs it runs fine

vivid marsh
#

try to set this in the api property type: () => ClassType

#

@ApiProperty({ type: () => ClassType})

past lance
#

That is the thing, I want swagger to infer the types from class-validator decorators

#

If I run the API with the cli tool it infers the types just fine

#

But if I start the API manually at runtime that error appears

astral sonnet
#

I'm pretty sure class-validator has nothing to do with this error

#

What do you mean by"start with the cli tool" and "start the API manually"

past lance
#

Not start the api file with the cli's nest start command

astral sonnet
#

So, nest start is returning the error?

#

If so, I'd assume tsx is adding in a resolution for the circular dependency that is being repeated

past lance
#

No nest start is running fine. Starting the full project with tsx is giving that error if I dont manually specify the types
And I dont want to do that when swagger can infer class-validator types

astral sonnet
#

But swagger can't infer from the class-validator types. Not by default at least

#

Nest has a cli plug-in that can, but that happens at the compile time step via adding type code to the files before they are compiled

past lance
astral sonnet
#

Yes, that shim is for the nest-cli plugin. It can be made to work with webpack as well, but generally isn't made to be compiler agnostic, so unless you are running nest start from within your tsx main file, that plugin is not being ran

past lance
#

And there is no way to run the plugin manually? Dang

astral sonnet
#

The plugin requires access to the source code so it can be modified as a stringg before sending it on to the compiler. It's really not ergonomic to try and mess with that