1

フラスコ、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- を送信します。

ヘッダー = コンテンツ タイプ、アプリケーション/json

本体 = [「テスト 1」、「テスト 2」、「テスト 3」]

取得: 422 Unprocessable Entity 要求は適切な形式でしたが、セマンティック エラーのため従うことができませんでした。

yml ファイルの swagger 定義、@use_kwargs パラメーター、またはテスト PUT に何か問題があると思います。

4

1 に答える 1