在swagger-editor中我可以控制是否发送空参数或不发送参数

时间:2017-08-14 07:33:31

标签: swagger-2.0 swagger-editor

Swagger-editor发送可选的数组参数,即使它们是空的。 有没有办法在Swagger 2.0中指定如果它是一个空数组则不发送可选参数?

请求的目标是Cats和/或Dogs列表的列表 - 这些都不是必需的

我希望如果请求只包含Cats,则调用者只会提供一个Cats列表,而不必发送一个空的Dogs列表。 昂首阔步编辑器强制执行空列表。

POST http://example:9090/api/testpath HTTP/1.1
Content-Type: application/json
{
  "Dogs": [
    1
  ],
  "Cats": []
}

我不确定这是否是有效请求。

POST http://example:9090/api/testpath HTTP/1.1
Content-Type: application/json
{
  "Dogs": [
    1
  ]
}

这是一个示例swagger规范

    {
    "swagger": "2.0",
    "info": {
        "title": "demo",
        "version": "Draft 0.1.0"
    },
    "host": "example:9090",
    "schemes": [
        "http",
        "https"
    ],
    "basePath": "/api",
    "produces": [
        "application/json"
    ],
    "paths": {
        "/testpath": {
            "post": {
                "summary": "Request with a complex target\n",
                "parameters": [
                    {
                        "name": "target",
                        "in": "body",
                        "required": true,
                        "description": "Array of collars and/or mobs to target with this request.",
                        "schema": {
                            "$ref": "#/definitions/TargetObjects"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The request was accepted."
                    }
                }
            }
        }
    },
    "definitions": {
        "TargetObjects": {
            "type": "object",
            "description": "Target of a request may be one or more objects or different types.\n",
            "properties": {
                "Dogs": {
                    "description": "A list of Dogs.",
                    "type": "array",
                    "items": {
                        "type": "number",
                        "format": "int64"
                    }
                },
                "Cats": {
                    "description": "A list of Pets.",
                    "type": "array",
                    "items": {
                        "type": "number",
                        "format": "int64"
                    }
                }
            }
        }
    }
}

0 个答案:

没有答案