2

I've created a python web API using flask, flasgger (swagger defined by yml files), and webargs:

@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

As a test I run my flask app and send an HTTP PUT-

header = Content-Type, application/json

body = ["test1", "test2", "test3"]

I get: 422 Unprocessable Entity The request was well-formed but was unable to be followed due to semantic errors.

I'm guessing something is either wrong with the swagger definition in the yml file, the @use_kwargs parameters, or my test PUT.

mlander
  • 51
  • 5

1 Answers1

2

So I figured this out myself.

Had to use: {"community_set": ["test1", "test2", "test3"]}

not just: ["test1", "test2", "test3"]

mlander
  • 51
  • 5