django-ninja
django-ninja copied to clipboard
embedding api docs into custom page
Hi.
I am using the autom.-generated docs function, from ninja API, to create a web-based, user friendly interface for the users visiting my page, as well as test facility.
I would like to embed that wonderful feature into my already existing custom web layout (header, footer, navbar, etc...). By so doing, I would have to reinvent the wheel and the user could use that standalone facility. Basically, I am missing a HOME button....
I am currently using django
Is that possible? Any examples?
Thanks. Marco
Hi @MM-cyi
You can create a custom docs viewer and override default template:
https://github.com/vitalik/django-ninja/blob/master/ninja/templates/ninja/swagger_cdn.html
you can render it like this:
from ninja.openapi.docs import Swagger
class MyDocs(Swagger):
template = 'path/to/my/template.html' # or template_cdn if you do not put 'ninja' to installed apps
api = NinjaAPI(docs=MyDocs())
or just use bare swagger ui (https://swagger.io/tools/swagger-ui/) as regular page and just use /api/openapi.json as SwaggerUIBundle.url
Hi vitalik.
Thank you for your kind and swift reply. I tried that in the past already, but when running the first line, I got:
----> 1 from ninja.openapi.docs import Swagger
ModuleNotFoundError: No module named 'ninja.openapi.docs'
I checked my ninja version and I have:
conda list | grep ninja
django-ninja 0.22.2 pypi_0 pypi
Importing Redocs wouldn't work neither.
Any suggestions?
well pluggable docs are added in ninja 1.x
for 0.22 what you can do
- add "ninja" to INSTALLED_APPS
- create template ninja/swagger.html on your templates folder and override it
or
or just use bare swagger ui (https://swagger.io/tools/swagger-ui/) as regular page and just use /api/openapi.json as SwaggerUIBundle.url configuration