API使用enum时Swagger验证错误



我有下面的Swagger文档(简化版本),有两个参数。TypeCode(字符串)和Status (enum)。当我尝试验证/导入到Azure Api管理时,我得到以下错误

Parsing error(s): JSON is valid against no schemas from 'oneOf'. Path 'paths['/Bids'].get.parameters[1]', line 1, position 188.

大摇大摆文档

{
"swagger": "2.0",
"info": {
"title": "/my-api",
"description": "My API",
"version": "1.0"
},
"paths": {
"/Bids": {
"get": {
"tags": [
"Bids"
],
"parameters": [
{
"in": "query",
"name": "typeCode",
"type": "string"
},
{
"in": "query",
"name": "status"
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
}   
},
"definitions": {
"MyApi.ApplicationCore.Filter.Status": {
"enum": [
"Submitted",
"Created",
"Cancelled",
"Accepted"
],
"type": "string"
}
}
}

我不确定是什么导致这个错误。我怀疑是与enum

有关

由于status参数缺少type属性而出现错误。因为你说这个参数应该是一个枚举,它还需要包含值列表的enum属性。虽然enum是在MyApi.ApplicationCore.Filter.Status模式中定义的,但是OpenAPI 2.0中的查询参数不能使用$ref模式,所以enum必须直接在status参数中定义。

正确版本:

"parameters": [
...
{
"in": "query",
"name": "status",
"type": "string",
"enum": [
"Submitted",
"Created",
"Cancelled",
"Accepted"
]
}
],

最新更新