rest_api_demo
rest_api_demo copied to clipboard
Swagger UI cannot expand operations
When trying to click on an operation (for example "get posts") Swagger is not able to expand the details, but seems to try to open an non-existant URL: http://localhost:8888/api/#!/blog%2Fposts/get_posts_collection
I looks as if the JavaScript sources did not load correctly. Are you seeing any errors in the Console or Network tabs of Dev Tools?
Nope, that was the idea of my animated gif, that you can see that there are no errors. For me the URL pattern issues for Swagger seems related on how flask-restplus is used in combination with Blueprint. As soon as I initialize the API without Blueprint, Swagger UI is happy.
So far, i was unable to reproduce your problem. Could you perhaps submit a pull request with the change you had to make to fix it?
I had the same issue, I resolved it by using the requirements.txt package version for flask-restplus, I had been using the most recent pip install version.
Possibly related to: https://github.com/noirbizarre/flask-restplus/issues/278
FYI it looks like the flask-restplus issue mentioned in the last comment is also breaking bravado client generation (see https://github.com/noirbizarre/flask-restplus/issues/278#issuecomment-302274508 )
It seems like an upstream issue, but could be worth fixing here as this tutorial is high up on search indexes for "Flask REST Swagger", and client generation is one of the main reasons to use Swagger.
This is a workaround:
diff --git a/rest_api_demo/api/blog/endpoints/categories.py b/rest_api_demo/api/blog/endpoints/categories.py
index 140d173..c974f56 100644
--- a/rest_api_demo/api/blog/endpoints/categories.py
+++ b/rest_api_demo/api/blog/endpoints/categories.py
@@ -9,7 +9,7 @@ from rest_api_demo.database.models import Category
log = logging.getLogger(__name__)
-ns = api.namespace('blog/categories', description='Operations related to blog categories')
+ns = api.namespace('blog_categories', path='/blog/categories', description='Operations related to blog categories')
@ns.route('/')
diff --git a/rest_api_demo/api/blog/endpoints/posts.py b/rest_api_demo/api/blog/endpoints/posts.py
index 0294c18..95f0313 100644
--- a/rest_api_demo/api/blog/endpoints/posts.py
+++ b/rest_api_demo/api/blog/endpoints/posts.py
@@ -10,7 +10,7 @@ from rest_api_demo.database.models import Post
log = logging.getLogger(__name__)
-ns = api.namespace('blog/posts', description='Operations related to blog posts')
+ns = api.namespace('blog_posts', path='/blog/posts', description='Operations related to blog posts')
@ns.route('/')