【问题标题】:Swagger/Swashbuckle not generating Tags element at rootSwagger/Swashbuckle 不在根目录生成标签元素
【发布时间】:2019-08-23 17:46:49
【问题描述】:

我们使用 Swashbuckle 在我们的 .NET API(不是核心)上设置了 Swagger。

我正在寻找 LucyBot 以制作一个更好看的文档页面。查看他们的示例,他们的 OpenAPI 文件在根目录中有一个“标签”元素,用于将显示分成组。我们的(/swagger/docs/v1)没有这样的元素。我已经尝试过使用 SwaggerConfig.cs 中可以看到的所有内容,但没有运气。

有什么简单的方法可以自动生成这个吗?一些选项,或 cmets,或者我只是忽略的东西?

  "swagger": "2.0",
  "info": {
    "description": "This is a demo of [LucyBot's API Documentation](http:\/\/lucybot.com) using swagger.io's Petstore server.  You can find out more about Swagger at [http:\/\/swagger.io](http:\/\/swagger.io) or on [irc.freenode.net, #swagger](http:\/\/swagger.io\/irc\/).  For this sample, you can use the api key `special-key` to test the authorization filters.\n\nTo use this documentation for your own API, visit [http:\/\/lucybot.com](http:\/\/lucybot.com)",
    "version": "1.0.0",
    "title": "Swagger Petstore",
    "termsOfService": "http:\/\/swagger.io\/terms\/",
    "contact": {
      "email": "apiteam@swagger.io"
    },
    "license": {
      "name": "Apache 2.0",
      "url": "http:\/\/www.apache.org\/licenses\/LICENSE-2.0.html"
    }
  },
  "host": "petstore.swagger.io",
  "basePath": "\/v2",
  "tags": [
    {
      "name": "pet",
      "description": "Everything about your Pets",
      "externalDocs": {
        "description": "Find out more",
        "url": "http:\/\/swagger.io"
      }
    },
    {
      "name": "store",
      "description": "Access to Petstore orders"
    },
    {
      "name": "user",
      "description": "Operations about user",
      "externalDocs": {
        "description": "Find out more about our store",
        "url": "http:\/\/swagger.io"
      }
    }
  ],```

【问题讨论】:

    标签: swagger openapi swashbuckle


    【解决方案1】:

    查看externalDocs的代码swashbuckle代码:
    https://github.com/domaindrivendev/Swashbuckle/blob/master/Swashbuckle.Core/Swagger/SwaggerDocument.cs#L134
    定义中有好东西,但没有在任何地方使用......

    我认为您唯一的选择是使用 IDocumentFilter 并注入您丢失的标签。
    以下是如何使用这些过滤器的示例: https://github.com/domaindrivendev/Swashbuckle/blob/5489aca0d2dd7946f5569341f621f581720d4634/Swashbuckle.Dummy.Core/SwaggerExtensions/AppendVersionToBasePath.cs

    【讨论】:

      猜你喜欢
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-30
      • 2016-07-11
      • 1970-01-01
      • 2019-12-23
      • 1970-01-01
      相关资源
      最近更新 更多