noirbizarre / flask-restplus

Fully featured framework for fast, easy and documented API development with Flask
http://flask-restplus.readthedocs.org
Other
2.74k stars 506 forks source link

Parse argument as a list #773

Closed glebmikulko closed 4 years ago

glebmikulko commented 4 years ago

I have the following model and parser:

component = api.model('Component', {
    'location': fields.String,
    'amount': fields.Integer,
})

...

parser = api.parser()
parser.add_argument('presented_argument', type=[component])
args = parser.parse_args()

I have error if I do it in this way: "'list' object is not callable"

What is the correct way to parse list?

Colin-b commented 4 years ago

If you dive into the code you will see that type argument is actually the callable responsible for converting the value received into the desired value. So you should, in your parser use the correct type, actually for a list of some type you can use action="append" as an additional parameter.

Please refer to the documentation of this project to learn how to use the argument parser.

Also, as stated in the readme, this project is not maintained anymore, if you plan on starting a new project, I would advise to start using the forked version flask-restx (again, this can be found in the readme).

Maybe the maintainers should consider updating the issue template so that it clearly states that this project is not maintained?

ziirish commented 4 years ago

Maybe the maintainers should consider updating the issue template so that it clearly states that this project is not maintained?

Good idea, I'll do that as well. Thanks