我使用以下规范获取错误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
我不理解错误或如何解决。
答案 0 :(得分:16)
您不能在type
参数中加入body
。这就是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": ""
}
}
}
}
}
答案 1 :(得分:0)
对我来说,导致错误的 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
*/
请注意,type
正下方有一个 parameters
当我将 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
*/