首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >验证错误:数据与'oneOf‘中的任何架构都不匹配

验证错误:数据与'oneOf‘中的任何架构都不匹配
EN

Stack Overflow用户
提问于 2015-05-15 06:35:57
回答 2查看 31.4K关注 0票数 22

我正在使用以下规范获取错误Data does not match any schemas from 'oneOf'

代码语言:javascript
复制
{
  "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验证器的完整错误:

代码语言:javascript
复制
#/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

我不明白这个错误,也不知道如何解决。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-05-15 13:30:09

不能在body参数中包含type。这就是为什么会有schema。试试这个:

代码语言:javascript
复制
{
  "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": ""
        }
      }
    }
  }
}
票数 20
EN

Stack Overflow用户

发布于 2021-06-03 22:40:44

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

代码语言:javascript
复制
/**
 * @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下时,它开始生效了:

代码语言:javascript
复制
/**
 * @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
 */
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30248604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档