【问题标题】:OpenApi couldn't resolve referenceOpenApi 无法解析引用
【发布时间】:2021-07-19 00:12:03
【问题描述】:

我正在学习 OpenApi。我从 Swagger 收到此错误:

TypeError: O 未定义 值参数-row.jsx:149 渲染 root-injects.jsx:93 反应 8 _renderValidatedComponentWithoutOwnerOrContext _renderValidatedComponent 执行初始安装 挂载组件 挂载组件 mount儿童 _createInitialChildren 挂载组件 根注入.jsx:95:14

我的json数据是:

{
    "components": {
        "parameters": {
          "q": {
            "in": "query", 
            "name": "q", 
            "style": "form"
          }
        }
    }, 
    "info": {
        "title": "OpenWeatherMap API"
    }, 
    "openapi": "3.0.2", 
    "paths": {
        "/weather": {
          "get": {
              "parameters": [
                {
                  "$ref": "#/components/parameters/q"
                }
              ]
          }
       }
   }
}

【问题讨论】:

    标签: swagger-ui openapi


    【解决方案1】:

    您的 API 定义缺少一些必需的关键字。如果将其粘贴到 https://editor.swagger.io 中,它将显示错误所在。

    具体来说,q 参数缺少schema(数据类型定义)。

    这是正确的版本:

    {
      "components": {
        "parameters": {
          "q": {
            "in": "query",
            "name": "q",
            "style": "form",
            "schema": {
              "type": "string"
            }
          }
        }
      },
      "info": {
        "title": "OpenWeatherMap API",
        "version": "1.0.0"
      },
      "openapi": "3.0.2",
      "paths": {
        "/weather": {
          "get": {
            "parameters": [
              {
                "$ref": "#/components/parameters/q"
              }
            ],
            "responses": {
              "200": {
                "description": "ok"
              }
            }
          }
        }
      }
    }
    

    【讨论】:

    • 谢谢,它通过添加缺少的schema 键来工作。并感谢您提供调试招摇的链接
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    • 2011-08-09
    相关资源
    最近更新 更多