djangodjango-rest-frameworkdjango-swagger

use django-rest-swagger 2 with custom swagger.json


I have a project build with django-rest-framework, and I want to use django-rest-swagger to get API documentation, so I made a swagger.json file via swagger editor, then my question is:

How can I make django-rest-swagger read and render my own swagger.json instead of auto-generated from code?

I've checked the django-rest-swagger doc over and over again but nothing found about that.

Any comment will be appreciated.


Solution

  • I know this is old post, but I ran into the same issue and wanted to provide my work around.

    If you are trying to create a Swagger UI from an external JSON, this was my work around. I am using django but wanted to provide the swagger api of another framework and server. Here are two options:

    1. The simplest solution is to just manually render the swagger html template and insert the endpoint url that provides the JSON inside SwaggerUi(), this is generally located in the last block.
    2. Alternatively, if you cannot access the json directly or have a static file, create your own rest end point that either reads the file, or makes the request to the remote server, and then itself serves up the desired JSON. Reference this endpoint in your swagger template.