marcgibbons / django-rest-swagger

Swagger Documentation Generator for Django REST Framework: deprecated
https://marcgibbons.com/django-rest-swagger/
BSD 2-Clause "Simplified" License
2.59k stars 599 forks source link

Having "definitions" route breaks SwaggerUI #671

Open quantoid opened 7 years ago

quantoid commented 7 years ago

Given I have an API with a bunch of routes including a "definitions" route that all go to a ModelViewSetthat use a HyperlinkedModelSerializer When I add a SwaggerUI route and view it Then I get no SwaggerUI using get_swagger_view unless I comment out the "definitions" route

router = DefaultRouter()
router.register("accounts", views.AccountViews)
router.register("people", views.PersonViews)
router.register("teams", views.TeamViews)
router.register("definitions", views.DefinitionViews)  # this breaks SwaggerUI

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^status/', healthcheck),
    url(r'^doc/', get_swagger_view(title="REST API")),
    url(r'^api/', include(router.urls)),
]

If there's something special about the "definitions" route I couldn't find it in the doco, other than there being a "definitions" section in a Swagger spec.

quantoid commented 7 years ago
screen shot 2017-07-04 at 7 53 38 pm
quantoid commented 7 years ago

There are no errors in the logs:

System check identified no issues (0 silenced).
July 04, 2017 - 09:53:14
Django version 1.11.2, using settings 'myservice.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[04/Jul/2017 09:53:33] "GET /doc/ HTTP/1.1" 200 4114
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/css/reset.css HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/jquery-1.8.0.min.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/css/screen.css HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/jquery.slideto.min.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/jquery.wiggle.min.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/css/print.css HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/css/typography.css HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/object-assign-pollyfill.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/jquery.ba-bbq.min.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/js-yaml.min.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/handlebars-2.0.0.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/lodash.min.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/backbone-min.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/highlight.9.1.0.pack.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/highlight.9.1.0.pack_extended.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/jsoneditor.min.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/marked.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/swagger-ui.min.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/lib/swagger-oauth.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/init.js HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /static/rest_framework_swagger/images/logo_small.png HTTP/1.1" 304 0
[04/Jul/2017 09:53:33] "GET /doc/?format=openapi HTTP/1.1" 200 9225
quantoid commented 7 years ago

Took a long process of elimination to work out that it was the route name!

davidmir commented 7 years ago

What did you have to do to fix the problem? I'm having the same problem ...

Thanks

quantoid commented 7 years ago

I changed the name of the route from "definitions" to "patterns".

router.register("patterns", views.DefinitionViews)  # this fixes SwaggerUI

Anything other than "definitions" seems to work.