Swagger UI-在禁用“尝试”按钮的情况下添加curl示例

问题描述

我正在使用Swagger UI为自定义REST API创建文档。

由于我不想使用它,所以我禁用了“试用”按钮,但我希​​望显示每个请求的curl命令。

有没有一种方法可以显示它而不激活“试用”按钮?或者在YAML文件添加一些内容,以在其中显示一个带有自定义文本的div?

解决方法

有没有一种方法可以显示它而不激活“试用”按钮?

不。 Swagger UI的curl命令生成器取决于“试用”的可用性,因为命令是根据用户在“试用”期间指定的特定参数值生成的。

或者在YAML文件中添加一些可以在其中显示自定义文本的div吗?

您可以使用操作的description字段添加细节,例如代码示例。说明支持Markdown用于RTF格式。

paths:
  /something:
    get:
      summary: Get something
      description: >-
        Detailed description goes here.


        And here's some code:

            curl https://example.com/something -H "Accept: application/json"

      responses:
        200:
          description: Successful response