【问题标题】:How to save fastify swagger api description to local file如何将 fastify swagger api 描述保存到本地文件
【发布时间】:2022-01-24 04:04:16
【问题描述】:

您好,启动项目时是否有可能将 API swagger YAML 保存到本地文件?我正在使用 fastify-swagger 插件

使用exposeRoute启用true并调用'/documentation/yaml' API允许通过浏览器下载YAML,但我需要在最初启动项目时生成此YAML文件并将其保存到项目内部。

【问题讨论】:

    标签: node.js api swagger swagger-ui fastify


    【解决方案1】:

    是的,你可以这样做:

    // .. 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)
    

    【讨论】:

      猜你喜欢
      • 2017-02-16
      • 2022-06-28
      • 2016-11-06
      • 2017-12-17
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多