rest_api_demo icon indicating copy to clipboard operation
rest_api_demo copied to clipboard

Swagger UI cannot expand operations

Open nikos opened this issue 7 years ago • 6 comments

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

swagger-open-problem

nikos avatar Feb 24 '17 07:02 nikos

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?

postrational avatar Feb 27 '17 19:02 postrational

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.

nikos avatar Feb 28 '17 09:02 nikos

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?

postrational avatar Mar 25 '17 19:03 postrational

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.

niko86 avatar Apr 03 '17 10:04 niko86

Possibly related to: https://github.com/noirbizarre/flask-restplus/issues/278

postrational avatar May 01 '17 13:05 postrational

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('/')

jwmullally avatar May 18 '17 01:05 jwmullally