noirbizarre / flask-restplus

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

How to document/model a POST endpoint with a plain raw body? #508

Open AndyMan1 opened 6 years ago

AndyMan1 commented 6 years ago

I'm trying to create a POST endpoint where the payload is just plain raw text. I can't seem to find a way to do so.

Essentially what I'd like is a swagger/flask-restplus way to handle the following curl command:

curl -X POST http://example.com/my/endpoint \
  -d hello world

It looks like the proper swagger to display this is possible, as seen here (scroll to Primitive Body heading): https://swagger.io/docs/specification/2-0/describing-request-body/

But I can't seem to manage this with either a Model or the RequestParser. Is this possible?

csandersdev commented 5 years ago

I would also like to be able to do this. As best as I can tell from the Swagger generation code (https://flask-restplus.readthedocs.io/en/stable/_modules/flask_restplus/swagger.html), the "consumes" is forced into a few hard-coded values and cannot be overridden. The default is application/json and each operation may override the consumes to either ['multipart/form'] or [application/x-www-form-urlencoded', 'multipart/form-data'], but never 'text/plain'.