【问题标题】:Is it possible to add a custom page in Swagger?是否可以在 Swagger 中添加自定义页面?
【发布时间】:2019-10-22 02:46:48
【问题描述】:

我正在使用 NestJS 构建 REST API,并使用 Swagger 模块生成文档。

Swagger 创建一个关于我所有路线的单页文档。我想在现有文档的顶部手动添加一些文档。有什么办法可以做到吗?

【问题讨论】:

    标签: swagger nestjs openapi


    【解决方案1】:

    如果您使用的是@nestjs/swagger 模块,您可以使用setDescription() 方法在SwaggerBaseConfig 对象(使用new DocumentBuilder() 创建)上添加支持降价的描述。您可以有一些看起来喜欢

      const document = new DocumentBuilder()
        .setTitle('My Api')
        .addTag('My Tag', 'The description for it')
        .setBasePath('/api')
        .setDescription('Here is where you can add extra documentation that will' +
            ' show up above the generated swagger file. You can make it as long' +
            ' or as short as you would like. You technically don\'t need to wrap' +
            ' the string either, it just makes things easier to read.'
        );
    

    关于模块can be found here 的大量重要信息和一个很好的(虽然基本的)示例can be seen on GitHub

    【讨论】:

      猜你喜欢
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      • 2020-03-08
      • 1970-01-01
      • 1970-01-01
      • 2022-10-18
      • 2014-04-22
      • 1970-01-01
      相关资源
      最近更新 更多