0

Hi is there is any possibility to save API swagger YAML to local file when starting the project? I'm using fastify-swagger plugin

using exposeRoute enable true and call '/documentation/yaml' API allowed to download YAML via the browser but i need to generate and save this YAML file to local inside the project when initially start the project.

chathun
  • 169
  • 1
  • 4
  • 12

1 Answers1

2

Yes, you can do it like this:

// .. your code
fastify.register(require('fastify-swagger'), { ... })
await fastify.listen(8080)

// after the ready or listen call
const yaml = fastify.swagger({ yaml: true })
require('fs').writeFileSync('./swagger.yml', yaml)
Manuel Spigolon
  • 11,003
  • 5
  • 50
  • 73