flask-smorest
flask-smorest copied to clipboard
Is it possible to use other objects than json in the request body?
Hi,
I am wondering if there is a way to have a list instead of the json object in the request body? My currect solution with a schema containing a field of type List looks like this:
{ "id_list": [ "3fa85f64-5717-4562-b3fc-2c963f66afa6" ] }
Desired request body schema:
["3fa85f64-5717-4562-b3fc-2c963f66afa6"]
Thank you.
I don't see how to do that.
I think last time I needed this I added a "data" key, like {"data": [my list of stuff]}
.
Using many=true for the schema and pre_load decorator I could I achieve this. But this workaround still has a problem because the example in the swagger documentation looks like
[ { "data": "3fa85f64-5717-4562-b3fc-2c963f66afa6" } ]
and I need it to be like
["3fa85f64-5717-4562-b3fc-2c963f66afa6"]
Is there any easy way to overwrite the example value in the documentation and have a custom example?
I just found out the answer to my question, there is an example method for the argument method of the blueprint decorator, so it just works.
This will only fix the example, not the documentation.
A lot of things can be achieved using pre/post_load/dump but those can't be automatically documented by apispec, of course.
I don't see how to document this without subclassing apispec stuff and overriding methods there (schema2jsonschema, most probably) to introduce a special case for your schema.
I just found out the answer to my question, there is an example method for the argument method of the blueprint decorator, so it just works.
hi, could you post your solution ? I needed this as well.
Sorry for the late response! If you look at flask_smorest.Blueprint.arguments, it has a parameter called example which was what I needed.
https://flask-smorest.readthedocs.io/en/latest/api_reference.html#flask_smorest.Blueprint.arguments