map*_*phe 4 swagger swagger-2.0
我试图在swagger中描述以下post参数:
{
"sources": [
{
"id": 101,
"parentId": 201
},{
"id": 102,
"parentId": 201
},{
"id": 102,
"parentId": 202
}
],
"destinationId": 301,
"param1": "value 1",
"param2": "value 2",
}
Run Code Online (Sandbox Code Playgroud)
问题是,这sources是一个对象数组,swagger似乎不支持.这是我尝试过的:
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
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个限制的任何想法?
Wil*_*son 14
如果我理解正确,您发布的请求正文是一个json对象而不是form.在这种情况下,您的招摇文档需要修改如下:
in: body而不是多个参数in: formData.in是body,schema则需要一个对象.schema.如果属性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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14475 次 |
| 最近记录: |