A Comprehensive Tutorial to Swagger - bounswe/bounswe2023group4 GitHub Wiki
Procedures:
We will be initially installing multiple libraries
In the terminal of the IDE you are using, write the following commands one by one
pip install pyyaml
pip install uritemplate
Go to urls.py in the API folder
add the following line
from rest_framework.schemas import get_schema_view
Add the following line in urlpatterns
path('api_schema',get_schema_view(title = 'API Schema', description = 'API documentation'), name = 'api_schema'),
Check the documentation after running the server
Use the link http://127.0.0.1:8000/api/api_schema
Install Swagger using the command
pip install django-rest-swagger
Go to the settings.py file
In the TEMPLATES list, insert the following line into DIR os.path.join(BASE_DIR, 'templates')
Under the API directory, create a new folder. Call it templates
In the templates folder, create the file docs.html
link "Check the third step."
Copy the code in theBack to the URL.py, add the following lines in urlpatterns
from django.views.generic import TemplateView
path('docs/', TemplateView.as_view( template_name='docs.html', extra_context={'schema_url':'api_schema'}), name='swagger-ui'),
Check the documentation after running the server
Use the link http://127.0.0.1:8000/api/docs/
References and additional resources:
Please refer to this video and this repo if you have additional questions. They were immensely helpful in preparing the guide.