【问题标题】:Show Swagger validation information显示 Swagger 验证信息
【发布时间】:2018-12-02 14:00:51
【问题描述】:

Swagger UI 不显示请求参数的验证信息。 我想显示参数的最小值、最大值、格式、模式(正则表达式)。有谁知道我在 Swagger UI 上如何表达参数的验证信息?

【问题讨论】:

  • 你是如何安装 Swagger UI 的?你是使用从repository 下载的原版版本(或通过 npm 安装),还是使用与某些框架/库(例如 Swashbuckle 或 Springfox)捆绑的 Swagger UI?

标签: rest api swagger


【解决方案1】:

假设您使用 Swagger UI 3.x(最新版本),请将 showCommonExtensions: true 添加到您的 index.html 文件中的 Swagger UI 初始化代码中:

const ui = SwaggerUIBundle({
  "dom_id": "#swagger-ui",
  url: "https://petstore.swagger.io/v2/swagger.json",
  showCommonExtensions: true,    // <-----
  ...

Learn more about Swagger UI configuration parameters.

【讨论】:

    【解决方案2】:

    通过使用 openapi 3.0.0,我得到了一个 UI,其中包含 http://editor.swagger.io/ 中显示的验证信息。从 openapi 2 到 openapi 3 的转换可以在以下 URL 完成。 https://mermade.org.uk/openapi-converter

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 1970-01-01
      • 2019-05-23
      • 2012-03-16
      • 1970-01-01
      • 1970-01-01
      • 2019-11-11
      相关资源
      最近更新 更多