2017-10-20 133 views
0

我使用燒瓶,flasgger(由陽明海運文件中定義招搖)創建一個python網絡API,並webargs:的Python瓶Flasgger(揚鞭)webargs - 在HTTP PUT體字符串列表

@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-

頭=內容類型,應用/ JSON

體= [ 「測試1」, 「TEST2」, 「TEST3」]

我得到: 422無法處理的實體 良好成形的請求,但由於語義錯誤而無法遵循。

我猜的東西是在yml文件,@use_kwargs參數或我的測試PUT中的swagger定義錯誤。

+0

您如何發送請求? –

回答

0

所以我想出了自己。

只好用: { 「community_set」:[ 「測試1」, 「TEST2」, 「TEST3」]}

不僅僅是: [ 「測試1」, 「TEST2」, 「TEST3」]