我正在使用以下规范获取错误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我不明白这个错误,也不知道如何解决。
发布于 2015-05-15 13:30:09
不能在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": ""
}
}
}
}
}发布于 2021-06-03 22:40:44
对我来说,是不正确的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
*/https://stackoverflow.com/questions/30248604
复制相似问题