#Can you run the swagger cli-plugin on nest BUILD?

14 messages · Page 1 of 1 (latest)

compact zinc
#

Right now, nest start will generate the our swagger JSON. But there is no way I can tell to run this during BUILD. We'd really like to generate the JSON swagger during build so we can use that JSON for other purposes.

Outside of starting nest and stopping it, is there any way to get that swagger plugin to run during build?

elfin oxide
#

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

bright jackal
#

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)

compact zinc
#

@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

bright jackal
#

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

elfin oxide
#

hat isn't using nest start and therefore does not use the swagger plugin
IIRC, the plugin is actually ran on build because it has to make use of the metadata available in tsc to properly add the decorators to the dist

bright jackal
compact zinc
#

that might work

#

so start nest up with the plugin, but pointing to a file that just starts the server and kills it

bright jackal
#

It's the entryFile