3

I'd like to customize the style (font, colors, logo, etc) of drf_yasg generated docs.

I see that I can extend drf_yasg/swagger-ui.html with the blocks extra_head, extra_styles, extra_body, extra_scripts, and can even overwrite the other blocks if I need to.

What I am not clear on is how I point to my template that extends swagger-ui.html.

I started with

class MyCustomSwaggerUIRenderer(SwaggerUIRenderer):
    template = 'api/custom-swagger-ui.html'

I want to replace SwaggerUIRenderer with MyCustomSwaggerUIRenderer in get_schema_view but do not understand how/where to do it without explicitly trying to enumerate all the other Renderers required too in some subclass of rest_framework.views.APIView and that seems convoluted.

Pointers to docs or examples are appreciated. I've already read https://drf-yasg.readthedocs.io/ without success.

Vishal
  • 2,097
  • 6
  • 27
  • 45

1 Answers1

4

You don't have to create a custom class for this. You just need to create a directory with the name drf-yasg under new or existing app and then place a file with the name swagger-ui.html underneath it with your custom template. For example, if you already have an app with the name api, you can just put it under api/templates/drf-yasg/swagger-ui.html. Make sure the app api is specified before drf-yasg in INSTALLED_APPS.

Reference: https://github.com/axnsan12/drf-yasg/issues/294#issuecomment-464461773

Chris Sam
  • 114
  • 6