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 1 pip install uritemplate 2

Go to urls.py in the API folder

3

add the following line

from rest_framework.schemas import get_schema_view 4

Add the following line in urlpatterns

path('api_schema',get_schema_view(title = 'API Schema', description = 'API documentation'), name = 'api_schema'), 5

Check the documentation after running the server

Use the link http://127.0.0.1:8000/api/api_schema 7

Install Swagger using the command

pip install django-rest-swagger 6

Go to the settings.py file

In the TEMPLATES list, insert the following line into DIR os.path.join(BASE_DIR, 'templates') 8

Under the API directory, create a new folder. Call it templates

In the templates folder, create the file docs.html

11

Copy the code in the link "Check the third step."

Back 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'), 11

Check the documentation after running the server

Use the link http://127.0.0.1:8000/api/docs/ 12

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.