#Can you run the swagger cli-plugin on nest BUILD?
14 messages · Page 1 of 1 (latest)
Not really, because there are some configuration options that it can end up relying on the runtime for, like the global prefix and versioning options. Most of the metadata exists at startup, but there is some that comes from possible configuration within main.ts so it's hard to actually not start a Nest server for it
What we do is create a separate entry point generate-swagger.ts that bootstraps the app using the same configuration as main.ts (the configuration is specified in a setup(app: INestApplication) function imported by both main and generate-swagger) without calling app.listen(), exports the swagger JSON and then exits via process.exit(). You can add it to the postbuild script to automate the workflow. (the easiest way is with ts-node src/generate.swagger.ts)
@bright jackal Question about that - if you do what you suggested - that isn't using nest start and therefore does not use the swagger plugin
how are you able to get the swagger cli plugin to work with that script?
We had what you suggested, but b/c it wasn't using nest start, it wasn't using the plugin, and therefore the JSON wasn't correct
Right, that might be a problem, we do not use the swagger cli plugin (it's too much magic for my liking)
but I think you can tell nest start to use a different entrypoint
hat isn't using nest start and therefore does not use the swagger plugin
IIRC, the plugin is actually ran onbuildbecause it has to make use of the metadata available in tsc to properly add the decorators to thedist
or you can supply an alternative nest-cli.json with the --config option: https://docs.nestjs.com/cli/usages#nest-start with a different entrypoint
that might work
so start nest up with the plugin, but pointing to a file that just starts the server and kills it
I don't actually see anything to specify the entrypoint in the nest-cli.json https://docs.nestjs.com/cli/monorepo#cli-properties
It's the entryFile