OpenApi 无法解析引用

时间:2021-07-19 00:12:03

标签: swagger-ui openapi

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

<块引用>

类型错误:O 未定义 值参数-row.jsx:149 渲染 root-injects.jsx:93 反应 8 _renderValidatedComponentWithoutOwnerOrContext _renderValidatedComponent 执行初始挂载 挂载组件 挂载组件 安装儿童 _createInitialChildren 挂载组件 root-injects.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"
                }
              ]
          }
       }
   }
}

screenshot

1 个答案:

答案 0 :(得分:0)

您的 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"
          }
        }
      }
    }
  }
}
相关问题