我使用flask,flasgger(由yml文件定义的swagger)和webargs创建了一个python web API:
@app.route('/api/set/', methods=['PUT'])
@swag_from('swagger/put_community_sets.yml')
@use_kwargs({'community_set': fields.List(fields.Str(),
location='json', required=True)})
def put_community_set(community_set):
print 'community_set to add: ' + str(community_set)
put_community_sets.yml:
tags:
- put community set API
parameters:
- name: body
in: body
schema:
id: put_community_set
required:
- community_set
properties:
community_set:
type: array
items:
type: string
description: the community set to be added
responses:
'200':
description: added a new community set
作为测试我运行我的烧瓶应用并发送HTTP PUT -
header = Content-Type,application / json
body = [“test1”,“test2”,“test3”]
我得到: 422不可处理的实体 该请求格式正确,但由于语义错误而无法遵循。
我猜测yml文件中的swagger定义,@ use_kwargs参数或我的测试PUT有问题。
答案 0 :(得分:0)
所以我自己想出来了。
不得不使用: {" community_set":[" test1"," test2"," test3"]}
不仅仅是: [" test1"," test2"," test3"]