简体   繁体   中英

Swagger Editor showing schema error: is not exactly one from definitions

Swagger editor showing the following error in the input JSON.

Schema error at paths./accord/stakeholderMaster/stakeholderLocationDetails.get.parameters[0] is not exactly one from <#/definitions/parameter>,<#/definitions/jsonReference>

Here is my 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"
              }
            }
          }
        }
      }
    }
  }
}

The error is caused by an incorrect combination of in , type and schema keywords in the parameter definition.

First of all, your operation is GET but has a request body ( "in": "body" parameter). Request body in GET does not have defined semantics .

I guess stakeHolderId is supposed to be either a path parameter:

GET /.../stakeholderLocationDetails/{stakeHolderId}

or a query parameter:

GET /.../stakeholderLocationDetails?stakeHolderId=12345

So the parameter should be "in": "path" or "in": "query" instead of "in": "body" . In case of a path parameter, also change the path to include the parameter name: "/accord/stakeholderMaster/stakeholderLocationDetails/{stakeHolderId}" . In case of a query parameter, leave the path as is (query parameters are not included in paths).

Also remove schema from the parameter definition. Path and query parameters use just the type ; the schema keyword is only used for body parameters.

More info: http://swagger.io/docs/specification/describing-parameters/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM