Swagger 招摇过市:描述字符串数组,其中元素是一组特定值的子集
我有以下JSON:Swagger 招摇过市:描述字符串数组,其中元素是一组特定值的子集,swagger,Swagger,我有以下JSON: { "animals": ["tiger", "bear"] } 动物数组可以是集合的任何子集 ["tiger", "lion", "elephant", "wolf", "fox", "bear", "zebra"] 但不能包含任何其他元素。以下语法受到限制,因为我丢失了有关元素可能具有的值的所有信息: { "description":"wild animals", "type": "array", "items": { "typ
{ "animals": ["tiger", "bear"] }
动物数组可以是集合的任何子集
["tiger", "lion", "elephant", "wolf", "fox", "bear", "zebra"]
但不能包含任何其他元素。以下语法受到限制,因为我丢失了有关元素可能具有的值的所有信息:
{
"description":"wild animals",
"type": "array",
"items": {
"type": "string"
}
}
有什么方法可以描述这一点吗?或者我应该把它记录在描述中
谢谢。您可以为它定义一个枚举。因此,您的定义如下所示
"WildAnimals": {
"description":"wild animals",
"type": "array",
"items": {
"$ref": "#/definitions/Animal"
}
},
"Animal": {
"type": "string",
"enum": ["tiger", "lion", "elephant", "wolf", "fox", "bear", "zebra"]
}