I am using Flask-Swagger with Flask-MongoRest. Last versions, with Python 3.8.2.
I wanted to simply try this code from the README:
from flask import Flask, jsonify
from flask_swagger import swagger
app = Flask(__name__)
@app.route("/spec")
def spec():
return jsonify(swagger(app))
then when I do GET http://127.0.0.1:5000/spec, the following error is displayed:
File "/home/cedric/.cache/pypoetry/virtualenvs/stats-api-7Yf7ZOUq-py3.8/lib/python3.8/site-packages/flask_swagger.py", line 178, in <lambda>
and verb in map(lambda m: m.lower(), endpoint.methods) \
AttributeError: type object 'Create' has no attribute 'lower'
I fixed my issue by changing this code:
https://github.com/gangverk/flask-swagger/blob/master/flask_swagger.py#L177-L179
to
if hasattr(endpoint, 'methods') \
and verb in map(lambda m: m.method.lower(), endpoint.methods) \
and hasattr(endpoint.view_class, verb):
Since actually here m is an object, not a string. m.method is a string. It also works with str(m).lower().
With this change, it works quite well.
If you want I can create a fix which will works with m.lower() and m.method.lower() and make a pull request.
Or do you thing the issue is on the side of Flask-MongoRest ?