我试图在swagger中描述以下post参数:
{
"sources": [
{
"id": 101,
"parentId": 201
},{
"id": 102,
"parentId": 201
},{
"id": 102,
"parentId": 202
}
],
"destinationId": 301,
"param1": "value 1",
"param2": "value 2",
}
问题在于sources
是一个对象数组,这些招摇似乎并不支持。这是我试过的:
paths:
/bulk-action:
post:
parameters:
- name: sources
in: formData
type: array
enum:
$ref: '#/definitions/BulkSource'
- name: destinationId
in: formData
type: integer
- name: param1
in: formData
type: string
- name: param2
in: formData
type: string
definitions:
BulkSource:
type: object
properties:
id:
type: integer
parentId:
type: integer
有关如何解决此限制的任何想法?
答案 0 :(得分:12)
如果我理解正确,您要发布的请求正文是json
对象,而不是form
。在这种情况下,您的招摇文档需要修改如下:
in: body
的参数而不是in: formData
的多个参数。 in
为body
,则需要schema
个对象。schema
下定义了json属性。如果属性type
为array
,则需要items
个对象。以下是一个例子:
paths:
/bulk-action:
post:
consumes:
- application/json
parameters:
- name: body
in: body
schema:
properties:
sources:
type: array
items:
$ref: '#/definitions/BulkSource'
destinationdId:
type: integer
responses:
200:
description: OK
definitions:
BulkSource:
type: object
properties:
id:
type: integer
parentId:
type: integer