我正在与Swagger的一个问题作斗争并且即将发疯......除了一个参数外,它主要起作用。情况如下:
我的API可以在网址中采用一些搜索限制。用户可以拥有多个搜索约束,并将它们作为查询字符串发送为数组(实际情况为here)。
我的Swagger Spec的这一部分存在问题(整个事情如下)
{
"name": "constraints",
"in": "query",
"description": "Search constraints",
"type": "array",
"items": {
"$ref": "#/definitions/search_constraints"
}
}
所以我想我有两个问题......
1)我是否尝试做一些Swagger不支持的事情(在URL的查询中有一个参数数组)
2)如果没有,我在做什么是错的?
我一直在http://editor2.swagger.io/中测试我的JSON,并且在错误旁边,它起作用,这意味着我可以测试执行搜索的调用并添加约束等。但是有错误阻止我使用readme.io和其他东西......
谢谢你们!
完整的JSON
{
"swagger": "2.0",
"info": {
"title": "example-api",
"version": "1.0.0"
},
"host": "xxx.com",
"basePath": "/api/1.1/meta/swagger.json/api/1.1",
"schemes": [
"https"
],
"consumes": [
"application/json"
],
"paths": {
"/obj/pet": {
"get": {
"description": "Retrieve a list of things of type pet with some optional search constraints. Retreives 100 items at most at once.",
"parameters": [
{
"name": "limit",
"in": "query",
"description": "Number of items to fetch (maximum is 100)",
"type": "integer",
"format": "int32",
"default": 50
},
{
"name": "cursor",
"in": "query",
"description": "Position to start from in the list",
"type": "integer",
"format": "int32",
"default": 0
},
{
"name": "sort_field",
"in": "query",
"description": "Field to sort the list on",
"type": "string"
},
{
"name": "descending",
"in": "query",
"description": "Sorting type: descending or ascending",
"type": "boolean"
},
{
"name": "constraints",
"in": "query",
"description": "Search constraints",
"type": "array",
"items": {
"$ref": "#/definitions/search_constraints"
}
}
],
"responses": {
"200": {
"description": "Retrieved list of pets",
"schema": {
"type": "object",
"properties": {
"results": {
"type": "array",
"items": {
"$ref": "#/definitions/pet"
}
},
"cursor": {
"type": "number",
"format": "float",
"description": "Rank of the first item in the list"
},
"count": {
"type": "number",
"format": "float",
"description": "Number of items in the current response. It is the minimum between the actual length of the list and the sent limit (or 100 if you did not specify a limit)."
},
"remaining": {
"type": "number",
"format": "float",
"description": "Number of remaining items after the current response. Useful to fetch more items."
}
}
}
}
}
}
}
},
"definitions": {
"pet": {
"type": "object",
"properties": {
"Name": {
"type": "string",
"description": "'Name' field of the current Pet"
},
"unique ID": {
"type": "string",
"description": "'unique ID' field of the current Pet"
}
}
},
"search_constraints": {
"type": "object",
"properties": {
"key": {
"type": "string",
"description": "Field to apply the search constraint on. Can be `_all` for a full-text search"
},
"constraint_type": {
"type": "string",
"description": "Type of constraint. Can be anything among `equals`, `not equal`, `is_empty`, `is_not_empty`, `text contains`, `not text contains`, `greater than`, `less than`, `in`, `not in`, `contains`, `not contains`, `empty`, `not empty`, `geographic_search`"
},
"value": {
"type": "string",
"description": "Value to compare to"
}
},
"required": [
"key",
"constraint_type"
]
}
}
}