Spaces:
Running
Running
luanpoppe
commited on
Commit
·
4cec855
1
Parent(s):
b700f35
feat: adicionando swagger para a API
Browse files- Dockerfile +2 -0
- endpoint_teste/views.py +6 -1
- requirements.txt +0 -0
- setup/settings.py +18 -4
- setup/urls.py +5 -1
Dockerfile
CHANGED
|
@@ -17,6 +17,8 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 17 |
|
| 18 |
# ENV PATH="/.venv/bin:$PATH"
|
| 19 |
|
|
|
|
|
|
|
| 20 |
RUN pip install uvicorn
|
| 21 |
CMD ["uvicorn", "setup.asgi:application", "--host", "0.0.0.0", "--port", "7860"]
|
| 22 |
|
|
|
|
| 17 |
|
| 18 |
# ENV PATH="/.venv/bin:$PATH"
|
| 19 |
|
| 20 |
+
RUN python manage.py collectstatic --noinput
|
| 21 |
+
|
| 22 |
RUN pip install uvicorn
|
| 23 |
CMD ["uvicorn", "setup.asgi:application", "--host", "0.0.0.0", "--port", "7860"]
|
| 24 |
|
endpoint_teste/views.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
-
import tempfile, os
|
| 2 |
from rest_framework import viewsets, filters
|
| 3 |
from django_filters.rest_framework import DjangoFilterBackend
|
| 4 |
from endpoint_teste.models import EndpointTesteModel
|
| 5 |
from endpoint_teste.serializer import EndpointTesteSerializer, PDFUploadSerializer
|
| 6 |
from setup.environment import default_model
|
|
|
|
| 7 |
|
| 8 |
from rest_framework.decorators import api_view
|
| 9 |
from rest_framework.response import Response
|
|
@@ -56,6 +57,10 @@ def getTeste(request):
|
|
| 56 |
print('result: ', result)
|
| 57 |
return Response(result)
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
@api_view(["POST"])
|
| 60 |
def getPDF(request):
|
| 61 |
if request.method == "POST":
|
|
|
|
| 1 |
+
import tempfile, os
|
| 2 |
from rest_framework import viewsets, filters
|
| 3 |
from django_filters.rest_framework import DjangoFilterBackend
|
| 4 |
from endpoint_teste.models import EndpointTesteModel
|
| 5 |
from endpoint_teste.serializer import EndpointTesteSerializer, PDFUploadSerializer
|
| 6 |
from setup.environment import default_model
|
| 7 |
+
from drf_spectacular.utils import extend_schema
|
| 8 |
|
| 9 |
from rest_framework.decorators import api_view
|
| 10 |
from rest_framework.response import Response
|
|
|
|
| 57 |
print('result: ', result)
|
| 58 |
return Response(result)
|
| 59 |
|
| 60 |
+
@extend_schema(
|
| 61 |
+
request=PDFUploadSerializer,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
@api_view(["POST"])
|
| 65 |
def getPDF(request):
|
| 66 |
if request.method == "POST":
|
requirements.txt
CHANGED
|
Binary files a/requirements.txt and b/requirements.txt differ
|
|
|
setup/settings.py
CHANGED
|
@@ -45,7 +45,8 @@ INSTALLED_APPS = [
|
|
| 45 |
"rest_framework",
|
| 46 |
"django_filters",
|
| 47 |
"corsheaders",
|
| 48 |
-
"endpoint_teste"
|
|
|
|
| 49 |
]
|
| 50 |
|
| 51 |
MIDDLEWARE = [
|
|
@@ -57,8 +58,11 @@ MIDDLEWARE = [
|
|
| 57 |
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
| 58 |
"django.contrib.messages.middleware.MessageMiddleware",
|
| 59 |
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
|
|
|
| 60 |
]
|
| 61 |
|
|
|
|
|
|
|
| 62 |
ROOT_URLCONF = "setup.urls"
|
| 63 |
|
| 64 |
TEMPLATES = [
|
|
@@ -141,6 +145,7 @@ USE_TZ = True
|
|
| 141 |
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
| 142 |
|
| 143 |
STATIC_URL = "static/"
|
|
|
|
| 144 |
|
| 145 |
# Default primary key field type
|
| 146 |
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
|
@@ -149,8 +154,8 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
| 149 |
|
| 150 |
CORS_ORIGIN_WHITELIST = [
|
| 151 |
"http://localhost",
|
| 152 |
-
"luanpoppe-projeto-y-teste-01.hf.space",
|
| 153 |
-
"
|
| 154 |
# "http://localhost:5000",
|
| 155 |
# "https://luan-pessoal.vercel.app",
|
| 156 |
# "http://localhost:5173",
|
|
@@ -158,5 +163,14 @@ CORS_ORIGIN_WHITELIST = [
|
|
| 158 |
|
| 159 |
REST_FRAMEWORK = {
|
| 160 |
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
| 161 |
-
'PAGE_SIZE': 10
|
|
|
|
| 162 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
"rest_framework",
|
| 46 |
"django_filters",
|
| 47 |
"corsheaders",
|
| 48 |
+
"endpoint_teste",
|
| 49 |
+
"drf_spectacular"
|
| 50 |
]
|
| 51 |
|
| 52 |
MIDDLEWARE = [
|
|
|
|
| 58 |
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
| 59 |
"django.contrib.messages.middleware.MessageMiddleware",
|
| 60 |
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
| 61 |
+
"whitenoise.middleware.WhiteNoiseMiddleware"
|
| 62 |
]
|
| 63 |
|
| 64 |
+
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
| 65 |
+
|
| 66 |
ROOT_URLCONF = "setup.urls"
|
| 67 |
|
| 68 |
TEMPLATES = [
|
|
|
|
| 145 |
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
| 146 |
|
| 147 |
STATIC_URL = "static/"
|
| 148 |
+
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
| 149 |
|
| 150 |
# Default primary key field type
|
| 151 |
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
|
|
|
| 154 |
|
| 155 |
CORS_ORIGIN_WHITELIST = [
|
| 156 |
"http://localhost",
|
| 157 |
+
"https://luanpoppe-projeto-y-teste-01.hf.space",
|
| 158 |
+
"https://*"
|
| 159 |
# "http://localhost:5000",
|
| 160 |
# "https://luan-pessoal.vercel.app",
|
| 161 |
# "http://localhost:5173",
|
|
|
|
| 163 |
|
| 164 |
REST_FRAMEWORK = {
|
| 165 |
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
| 166 |
+
'PAGE_SIZE': 10,
|
| 167 |
+
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
|
| 168 |
}
|
| 169 |
+
|
| 170 |
+
SPECTACULAR_SETTINGS = {
|
| 171 |
+
'TITLE': 'Your Project API',
|
| 172 |
+
'DESCRIPTION': 'Your project description',
|
| 173 |
+
'VERSION': '1.0.0',
|
| 174 |
+
'SERVE_INCLUDE_SCHEMA': False,
|
| 175 |
+
# OTHER SETTINGS
|
| 176 |
+
}
|
setup/urls.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
from django.contrib import admin
|
| 2 |
from django.urls import path, include
|
| 3 |
from rest_framework import routers
|
|
|
|
|
|
|
| 4 |
|
| 5 |
from endpoint_teste.views import EndpointTesteViewSet, getTeste, getPDF
|
| 6 |
|
|
@@ -8,8 +10,10 @@ router = routers.DefaultRouter()
|
|
| 8 |
# router.register("endpoint-teste", EndpointTesteViewSet, basename="Basename do endpoint-teste")
|
| 9 |
|
| 10 |
urlpatterns = [
|
|
|
|
|
|
|
| 11 |
path("admin/", admin.site.urls),
|
| 12 |
path('', include(router.urls)),
|
| 13 |
path("teste", getTeste),
|
| 14 |
path('pdf', getPDF, name='upload-pdf')
|
| 15 |
-
]
|
|
|
|
| 1 |
from django.contrib import admin
|
| 2 |
from django.urls import path, include
|
| 3 |
from rest_framework import routers
|
| 4 |
+
from drf_spectacular.views import SpectacularSwaggerView, SpectacularAPIView
|
| 5 |
+
|
| 6 |
|
| 7 |
from endpoint_teste.views import EndpointTesteViewSet, getTeste, getPDF
|
| 8 |
|
|
|
|
| 10 |
# router.register("endpoint-teste", EndpointTesteViewSet, basename="Basename do endpoint-teste")
|
| 11 |
|
| 12 |
urlpatterns = [
|
| 13 |
+
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
|
| 14 |
+
path('swagger/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
|
| 15 |
path("admin/", admin.site.urls),
|
| 16 |
path('', include(router.urls)),
|
| 17 |
path("teste", getTeste),
|
| 18 |
path('pdf', getPDF, name='upload-pdf')
|
| 19 |
+
]
|