python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.16k stars 335 forks source link

Using flask-restx for nameless input arguments #491

Open jedrek-VL opened 1 year ago

jedrek-VL commented 1 year ago

Hi, I am using flask-restx to build an app which receives a JSON-formatted string via a POST request. Currently, the relevant piece of code in the app reads:

api = Api(app, authorizations=authorizations, security='bearerToken')
request_parser = api.parser()
request_parser.add_argument('input_data', location='json', required=True)

This correctly handles requests of the form:

curl  -d '{"input_data": [0.0, 0.5, 1.0]}' -H "Content-Type: application/json" …

and Swagger documentation is generated correctly.

However, I would like the app to respond to simpler requests like:

curl  -d '[0.0, 0.5, 1.0]' -H "Content-Type: application/json" …

and still have correct Swagger documentation. I know how to do it just by calling request.get_json(), but I'd prefer to use flask-restx. I've gone through the flask-restx docs but couldn't see how to do it. Any pointers will be greatly appreciated :)