2017-10-20 1 views
0

HTTP의 PUT 본문에 문자열 목록 및 webargs :파이썬 플라스크 Flasgger (자신감)은 webargs - 나는 플라스크, flasgger (YML 파일에 의해 정의 된 자신감)를 사용하여 파이썬 웹 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 : 내 플라스크 응용 프로그램을 실행하고 HTTP PUT-

를 보내 테스트로

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 

헤더 = 콘텐츠 형식, 응용 프로그램/JSON

몸 = [ "TEST1", "TEST2", "TEST3"]

내가 얻을 : (422) 처리 할 수 ​​없음이 엔티티 요청이 잘 형성하지만, 의미 론적 오류로 인해 따라갈 수 없었습니다.

yml 파일의 swagger 정의, @use_kwargs 매개 변수 또는 테스트 PUT에 문제가있는 것으로 생각됩니다.

+0

요청을 어떻게 보내시겠습니까? –

답변

0

그래서 나는 이것을 알아 냈습니다.

를 사용했다 : { "community_set"[ "TEST1", "TEST2", "TEST3"]}

아니라 : [ "TEST1", "TEST2", "TEST3"]