显示模式错误的Swagger编辑器:不完全是定义中的错误

时间:2017-05-16 02:33:43

标签: json swagger swagger-editor

Swagger编辑器在输入JSON中显示以下错误。

paths./accord/stakeholderMaster/stakeholderLocationDetails.get.parameters [0]中的模式错误 不是<#/ definitions / parameter>中的一个,<#/ definitions / jsonReference>

这是我的JSON,

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "Title",
    "description": "description"
  },
  "basePath": "/api",
  "paths": {
    "/accord/stakeholderMaster/stakeholderLocationDetails": {
      "get": {
        "description": "Returns stakeholder location details",
        "operationId": "findMovies",
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "in": "body",
            "name": "stakeHolderId",
            "description": "Stakeholder ID",
            "required": true,
            "type": "integer",
            "schema": {
              "$ref": "#/definitions/stakeHolder"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful operation",
            "schema": {
              "$ref": "#/definitions/stakeHolder"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "stakeHolder": {
      "type": "object",
      "properties": {
        "stakeHolderId": {
          "type": "integer"
        },
        "chartTerm": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "label": {
                "type": "string"
              },
              "value": {
                "type": "string"
              }
            }
          }
        },
        "chartContent": {
          "type": "object",
          "properties": {
            "countSeriesOne": {
              "type": "array",
              "items": {
                "type": "integer"
              }
            },
            "nameSeriesOne": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "chartLimit": {
              "type": "integer"
            },
            "receivableChartTerm": {
              "type": "integer"
            },
            "payableChartTerm": {
              "type": "integer"
            },
            "chartTerm": {
              "type": "integer"
            },
            "urlList": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:2)

错误是由参数定义中intypeschema关键字的错误组合引起的。

首先,您的操作是GET,但有一个请求体("in": "body"参数)。在GET does not have defined semantics中请求正文。

我猜stakeHolderId应该是路径参数:

GET /.../stakeholderLocationDetails/{stakeHolderId}

或查询参数:

GET /.../stakeholderLocationDetails?stakeHolderId=12345

因此,参数应为"in": "path""in": "query",而不是"in": "body"。如果是路径参数,还要更改路径以包含参数名称:"/accord/stakeholderMaster/stakeholderLocationDetails/{stakeHolderId}"。如果是查询参数,请保持路径不变(查询参数不包含在路径中)。

同时从参数定义中删除schema。路径和查询参数仅使用type; schema关键字仅用于身体参数。

更多信息: http://swagger.io/docs/specification/describing-parameters/