首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >(Swagger) webargs - HTTP PUT body中的String列表

(Swagger) webargs - HTTP PUT body中的String列表
EN

Stack Overflow用户
提问于 2017-10-20 22:22:30
回答 1查看 1.5K关注 0票数 2

我使用烧瓶、flasgger ( yml文件定义的swagger)和webargs创建了python:

代码语言:javascript
复制
@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:

代码语言:javascript
复制
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

header = Content-Type,application/json

body = "test1“、"test2”、"test3“

我得到: 422个不可处理实体,请求格式良好,但由于语义错误无法遵循。

我猜想yml文件中的swagger定义、@use_kwargs参数或我的测试输出可能有问题。

EN

回答 1

Stack Overflow用户

发布于 2017-10-22 05:10:41

所以我自己想出来了。

必须使用:{"community_set":"test1“、"test2”、"test3"}

不仅仅是:"test1“、"test2”、"test3“

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46858123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档