【发布时间】:2018-04-02 03:47:15
【问题描述】:
我使用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 = 内容类型,应用程序/json
body = ["test1", "test2", "test3"]
我得到: 422 无法处理的实体 该请求格式正确,但由于语义错误而无法执行。
我猜测 yml 文件中的 swagger 定义、@use_kwargs 参数或我的测试 PUT 有问题。
【问题讨论】:
-
你是如何发送请求的?
标签: python flask swagger flasgger webargs