Validation error: Data does not match any schemas from 'oneOf'

Validation error: Data does not match any schemas from 'oneOf'

我收到以下规格的错误 Data does not match any schemas from 'oneOf'

{
  "info": {
    "version": "1.0.0",
    "title": "REST API"
  },
  "paths": {
    "/doit": {
      "post": {
        "responses": {
          "200": {
            "description": "Successful response"
          }
        },
        "parameters": [
          {
            "type": "object",
            "schema": {
              "$ref": "#/definitions/ResponseDefinition"
            },
            "required": "true",
            "name": "docs",
            "in": "body"
          }
        ]
      }
    }
  },
  "swagger": "2.0",
  "definitions": {
    "ResponseDefinition": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string",
          "description": ""
        }
      }
    }
  }
}

来自 swagger-tools 验证器的完整错误:

#/paths/~1doit/post/parameters/0: Data does not match any schemas from 'oneOf'
#/paths/~1doit/post/parameters/0: Data does not match any schemas from 'oneOf'
  #/required: Expected type boolean but found type string
  #/: Missing required property: type
#/paths/~1doit/post/parameters/0: Additional properties not allowed: in,name,required,schema

我不明白错误或如何解决。

您不能在 body 参数中包含 type。这就是 schema 的原因。试试这个:

{
  "info": {
    "version": "1.0.0",
    "title": "REST API"
  },
  "paths": {
    "/doit": {
      "post": {
        "responses": {
          "200": {
            "description": "Successful response"
          }
        },
        "parameters": [
          {
            "schema": {
              "$ref": "#/definitions/ResponseDefinition"
            },
            "required": "true",
            "name": "docs",
            "in": "body"
          }
        ]
      }
    }
  },
  "swagger": "2.0",
  "definitions": {
    "ResponseDefinition": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string",
          "description": ""
        }
      }
    }
  }
}

对我来说,是不正确的 apidoc 导致了错误。该文档产生了错误:

/**
 * @openapi
 * /init:
 *   get:
 *     description: Tells the app an environment it should use
 *     parameters:
 *       - name: version
 *         in: query
 *         description: app version, for example "4.0.0"
 *         required: true
 *         type: string
 *     responses:
 *       200:
 *         description: Description
 */

请注意 parameters

正下方有一个 type

当我把 type 放在 parameters 下 -> schema 它开始有效:

/**
 * @openapi
 * /init:
 *   get:
 *     description: Tells the app an environment it should use
 *     parameters:
 *       - name: version
 *         in: query
 *         description: app version, for example "4.0.0"
 *         required: true
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: Description
 */