Skip to content

Commit 308ef9d

Browse files
committed
feat(swagger): add swagger documentation to project
-add drf-yasg and swagger to packages and requirements -add swagger urls -add static files Option for swagger
1 parent 1c07fcc commit 308ef9d

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ This is a django app for scraping data from specified digikala search urls.
1818

1919
`python manage.py runserver`
2020

21-
#API Guide
21+
# API Guide
22+
23+
**You can use </api/doc> for swagger documentation**
2224

2325
- **URL**
2426

@@ -34,9 +36,8 @@ This is a django app for scraping data from specified digikala search urls.
3436

3537
- **Data Params**
3638

37-
- requierd:
38-
39-
digikala search url such as:
39+
- requierd
40+
digikala search url such as:
4041

4142
`category=https://www.digikala.com/search/?q=%D8%B4%DB%8C%D8%A7%D8%A6%D9%88%D9%85%DB%8C`
4243

@@ -47,4 +48,4 @@ This is a django app for scraping data from specified digikala search urls.
4748

4849
`pages=15`
4950

50-
(default is 5)
51+
(default is 5)

kernel/settings/base.py

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
'django.contrib.auth.context_processors.auth',
3232
'django.contrib.messages.context_processors.messages',
3333
],
34+
'libraries': { # Adding this section should work around the issue.
35+
'staticfiles' : 'django.templatetags.static',
36+
},
3437
},
3538
},
3639
]

kernel/settings/packages.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
'warehouse'
1313
]
1414
THIRD_PARTY_PACKAGES = [
15-
'rest_framework'
15+
'rest_framework',
16+
'rest_framework_swagger',
17+
'drf_yasg'
1618
]
1719

1820
INSTALLED_APPS = DEFAULT_APPS + LOCAL_APPS + THIRD_PARTY_PACKAGES
@@ -32,6 +34,7 @@
3234
# 'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning',
3335
# 'ALLOWED_VERSIONS': ('1.0',),
3436
# Pagination
37+
'DEFAULT_SCHEMA_CLASS':'rest_framework.schemas.coreapi.AutoSchema',
3538
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
3639
'PAGE_SIZE': 100
3740
}

requirements.txt

+15
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,32 @@ cffi==1.15.0
1010
charset-normalizer==2.0.12
1111
colorama==0.4.4
1212
constantly==15.1.0
13+
coreapi==2.3.3
14+
coreschema==0.0.4
1315
cryptography==36.0.1
1416
cssselect==1.1.0
1517
Django==4.0.3
18+
django-rest-swagger==2.2.0
1619
djangorestframework==3.13.1
20+
drf-yasg==1.20.0
1721
fake-useragent==0.1.11
1822
filelock==3.6.0
1923
h11==0.13.0
2024
hyperlink==21.0.0
2125
idna==3.3
2226
importlib-metadata==4.11.2
2327
incremental==21.3.0
28+
inflection==0.5.1
2429
itemadapter==0.4.0
2530
itemloaders==1.0.4
31+
itypes==1.2.0
32+
Jinja2==3.0.3
2633
jmespath==0.10.0
2734
lxml==4.8.0
35+
MarkupSafe==2.1.0
36+
openapi-codec==1.3.2
2837
outcome==1.1.0
38+
packaging==21.3
2939
parse==1.19.0
3040
parsel==1.6.0
3141
Protego==0.2.1
@@ -35,6 +45,7 @@ pycparser==2.21
3545
PyDispatcher==2.0.5
3646
pyee==8.2.2
3747
pyOpenSSL==22.0.0
48+
pyparsing==3.0.7
3849
pyppeteer==1.0.2
3950
pyquery==1.4.3
4051
PySocks==1.7.1
@@ -44,9 +55,12 @@ queuelib==1.6.2
4455
requests==2.27.1
4556
requests-file==1.5.1
4657
requests-html==0.10.0
58+
ruamel.yaml==0.17.21
59+
ruamel.yaml.clib==0.2.6
4760
Scrapy==2.6.1
4861
selenium==4.1.2
4962
service-identity==21.1.0
63+
simplejson==3.17.6
5064
six==1.16.0
5165
sniffio==1.2.0
5266
sortedcontainers==2.4.0
@@ -61,6 +75,7 @@ twisted-iocpsupport==1.0.2
6175
typing_extensions==4.1.1
6276
tzdata==2021.5
6377
Unidecode==1.3.3
78+
uritemplate==4.1.1
6479
urllib3==1.26.8
6580
w3lib==1.22.0
6681
websockets==10.2

warehouse/api/urls.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from django.urls import (
22
path,
3+
re_path,
34
include
45
)
56

67
from rest_framework import routers
8+
from drf_yasg.views import get_schema_view
9+
from drf_yasg import openapi
710

811
from warehouse.api.views import(
912
ProductViewSet,
@@ -19,7 +22,22 @@
1922
router.register(r'colors', ColorViewSet)
2023
router.register(r'guarantees', GuaranteeViewSet)
2124

25+
schema_view = get_schema_view(
26+
openapi.Info(
27+
title="Digikala Crawler",
28+
default_version="V1",
29+
description="API documentation for project",
30+
terms_of_service="https://www.google.com/policies/terms/",
31+
),
32+
public=True,
33+
)
34+
2235
urlpatterns = [
2336
path('', include(router.urls)),
24-
path('category/',CategoryView.as_view() )
25-
]
37+
path('category/',CategoryView.as_view()),
38+
39+
#for documentation
40+
re_path(r'^doc/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
41+
42+
]
43+

0 commit comments

Comments
 (0)