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

Swagger UI doesn't work in 2.0.0 #477

Closed excieve closed 8 years ago

excieve commented 8 years ago

Just upgraded to DRF 3.4.0 and DRS 2.0.0, after reconfiguring according to the example app the Swagger UI shows the header and an empty page. Lots of 404s in the network log and indeed the base template seems to load many JS files that don't exist anymore.

GET 
http://localhost:8080/static/rest_framework_swagger/css/typography.css [HTTP/1.0 200 OK 4ms]
GET 
http://localhost:8080/static/rest_framework_swagger/css/reset.css [HTTP/1.0 200 OK 7ms]
GET 
http://localhost:8080/static/rest_framework_swagger/css/screen.css [HTTP/1.0 200 OK 21ms]
GET 
http://localhost:8080/static/rest_framework_swagger/css/print.css [HTTP/1.0 200 OK 17ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/object-assign-pollyfill.js [HTTP/1.0 200 OK 15ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/jquery-1.8.0.min.js [HTTP/1.0 404 Not Found 28ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/jquery.slideto.min.js [HTTP/1.0 404 Not Found 25ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/jquery.wiggle.min.js [HTTP/1.0 404 Not Found 25ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/jquery.ba-bbq.min.js [HTTP/1.0 404 Not Found 21ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/handlebars-2.0.0.js [HTTP/1.0 200 OK 19ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/js-yaml.min.js [HTTP/1.0 200 OK 19ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/lodash.min.js [HTTP/1.0 200 OK 17ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/backbone-min.js [HTTP/1.0 404 Not Found 22ms]
GET 
http://localhost:8080/static/rest_framework_swagger/swagger-ui.js [HTTP/1.0 200 OK 162ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/highlight.9.1.0.pack.js [HTTP/1.0 200 OK 14ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/highlight.9.1.0.pack_extended.js [HTTP/1.0 200 OK 17ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/jsoneditor.min.js [HTTP/1.0 200 OK 30ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/marked.js [HTTP/1.0 200 OK 26ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/swagger-oauth.js [HTTP/1.0 404 Not Found 29ms]
GET 
http://localhost:8080/static/rest_framework_swagger/init.js [HTTP/1.0 200 OK 22ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/jquery-1.8.0.min.js [HTTP/1.0 404 Not Found 7ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/jquery.slideto.min.js [HTTP/1.0 404 Not Found 5ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/jquery.wiggle.min.js [HTTP/1.0 404 Not Found 6ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/jquery.ba-bbq.min.js [HTTP/1.0 404 Not Found 6ms]
GET 
http://localhost:8080/static/rest_framework_swagger/lib/backbone-min.js [HTTP/1.0 404 Not Found 5ms]
ReferenceError: $ is not defined
 swagger-ui.js:120:1
GET 
http://localhost:8080/static/rest_framework_swagger/lib/swagger-oauth.js [HTTP/1.0 404 Not Found 4ms]
GET 
http://localhost:8080/static/rest_framework_swagger/images/logo_small.png [HTTP/1.0 200 OK 2ms]
ReferenceError: $ is not defined
marcgibbons commented 8 years ago

@excieve Well that was embarrassing, lib was in my gitignore file. Pushed 2.0.1. Should be fixed!

excieve commented 8 years ago

@marcgibbons It works now, thanks for a quick response! Except API itself looks very incomplete now... but I suppose that's not in DRS' domain anymore.

marcgibbons commented 8 years ago

@excieve Thank YOU for flagging this!

Correct. This is being pushed up to to CoreAPI and Django REST which doesn't have all the features previously available in DRS, but this is actively being developed. I'll be working towards allowing overrides and additional configuration in this project (i.e. Swagger specific settings) which may not be part of the CoreAPI specification.

Would be good to start a whishlist :)

excieve commented 8 years ago

Well, the biggest issue so far is missing resources, which have IsAuthenticated permission class (default in my case). Then docstrings don't seem to make their way into the descriptions. Also I know YAML config in the docstrings is deprecated but I've been using this a lot to specify special cases like params not in serializer, response messages, omit serializers in some custom view set views, omit parameters when serializer is only used for response, etc. There should be some way to configure all this IMO.

excieve commented 8 years ago

API resources that require authentication only display if I put the session auth class into the DRF configs and authenticate my user. But this doesn't really make sense since I want the whole API documentation to be available regardless of whether it needs auth when used or not. Also I'm using JWT auth exclusively for the API and don't really want session auth to be available for it.

marcgibbons commented 8 years ago

Great feedback. The authentication issue should be solvable in the current version.

I want the whole API documentation to be available regardless of whether it needs auth

This can be achieved by omitting the request context from the schema generator.

@api_view()
@renderer_classes([renderers.CoreJSONRenderer])
def schema_view(request):
    return generator.get_schema()

I'm using JWT auth exclusively for the API and don't really want session auth to be available for it

Great! Although JWT is not supported by Swagger, if you have a token, or some other payload you can configure the authorization to accept your token.

You should be able to do all this by customizing SWAGGER_SETTINGS.

SWAGGER_SETTINGS = {
    'USE_SESSION_AUTH': False,
    'SECURITY_DEFINITIONS': {
         'jwt': {
              'type': 'apiKey',
              'name': 'Authorization',
              'in': 'header'
         }
    }
}

(The security definition comes from the Swagger/OpenAPI 2.0 specification)

For docstrings / description, I'd expect this to be coming from Django REST Framework soon.

Hope this helps!

excieve commented 8 years ago

This can be achieved by omitting the request context from the schema generator.

Thanks for this! Would be great to document it in DRS. Speaking of which, I think the example in the quick start doesn't really work (at least it didn't for me, while the one in example app works).

Although JWT is not supported by Swagger, if you have a token, or some other payload you can configure the authorization to accept your token.

Yes, I'm aware of this and using in 0.3. It was just in the context of auth-requiring resources not being rendered.

marcgibbons commented 8 years ago

You are 100% correct. I will update the docs - I think this needs to be updated in DRF as well.

seclace commented 7 years ago

Hi all! I add JWT authorization in swagger, but how can I save this when reloading the page? I beleive there is some approach to make it may be with overriding template, but how can I override it?