PWZER / swagger-ui-py

Swagger UI for Python web framework, such Tornado, Flask and Sanic. https://pwzer.github.io/swagger-ui-py/
https://pypi.org/project/swagger-ui-py
Apache License 2.0
68 stars 31 forks source link

AttributeError: 'PosixPath' object has no attribute 'rstrip' #13

Closed pasqLisena closed 4 years ago

pasqLisena commented 4 years ago

Hello,
I am recently facing this error when using swagger-ui.

Traceback (most recent call last):
  File "app/project.py", line 14, in <module>
    api_doc(app, config_path='swagger.yml', url_prefix='', title='Topic Model API')
  File "/usr/local/lib/python3.7/site-packages/swagger_ui/core.py", line 36, in __init__
    self._auto_match_handler()
  File "/usr/local/lib/python3.7/site-packages/swagger_ui/core.py", line 273, in _auto_match_handler
    return self._flask_handler()
  File "/usr/local/lib/python3.7/site-packages/swagger_ui/core.py", line 122, in _flask_handler
    static_folder=self.static_dir, static_url_path='/'
  File "/usr/local/lib/python3.7/site-packages/flask/blueprints.py", line 187, in __init__
    self.static_folder = static_folder
  File "/usr/local/lib/python3.7/site-packages/flask/helpers.py", line 1004, in static_folder
    value = value.rstrip("/\\")
AttributeError: 'PosixPath' object has no attribute 'rstrip'

I use swagger_ui in this way:

from swagger_ui import api_doc

app = Flask(__name__)
CORS(app)
api_doc(app, config_path='swagger.yml', url_prefix='', title='Topic Model API')

Trying to understand the problem, I am seeing that self.static_dir is indeed a PosixPath. The problem is solved inserting in core.py@line120 the cast to str:

swagger_blueprint = Blueprint(
            'swagger_blueprint', __name__, url_prefix=self._url_prefix,
            static_folder=str(self.static_dir), static_url_path='/'
        )
PWZER commented 4 years ago

@pasqLisena Fix on v0.3.0.