I am documenting my response models, and need to show the api returns list of string.
["user1","user2"]
but the model requires a dictionary(json) format, as follow:
ns.response(200,'Success', NS.model("my_get_model",[{
"name": fields.String(example="user1"),
}]))
I have tried following codes but none of them work:
ns = Namespace('My Apis')
ns.response(200,'Success', [ns.model("my_get_model",
fields.String(example="user1")
)])
or
ns.response(200,'Success', ["user1"])
or
ns.response(200,'Success', ns.model("my_get_model",fields.List(fields.String(example="user1"))))
Please advice.
FastAPI surpasses Flask in terms of performance, and it is one of the fastest Python web frameworks. Only Starlette and Uvicorn are faster. Because of ASGI, FastAPI supports concurrency and asynchronous code by declaring the endpoints. For concurrent programming, Python 3.4 introduced Async I/O.
marshal_with() is a convenience decorator, that is functionally equivalent to: class Todo(Resource): def get(self, **kwargs): return marshal(db_get_todo(), model), 200. The @api. marshal_with decorator add the swagger documentation ability.
namespace is from the Flask-RESTPlus and Blueprint is from flask to organize your app. the namespaces modules (specific to Flask-RESTPlus) are reusable namespaces designed like you would do with Flask's Blueprint.
I think this is what you need: https://github.com/python-restx/flask-restx/issues/65
Try simply passing in fields.List
without wrapping a model.
ns.response(200, 'Success', fields.List(fields.String(example="user1")))
FYI, flask-restx
is a fork of flask-restplus
and it should have more updated features since flask-restplus
is no longer being maintained due to the developers no able to contact flask-restplus
's project owner.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With