Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Func/swagger 13 #12

Merged
merged 8 commits into from
Sep 25, 2024
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ __pycache__/
/node_modules
.env
.pytest_cache
__pycache__
__pycache__
schema.yml
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Base de conhecimento TUPAN-BACK


## Ambiente

### Criar, ativar e instalar as dependencias do ambiente virtual
Expand All @@ -21,6 +20,17 @@ cp ./src/.env_sample ./src/.env
```
Logo em seguida altere as variáveis para os valores desejados.

## Swagger

### Gerando o schema para o swagger
Execute o seguinte comando no terminal para gerar o .yml que será utilizado pelo swagger:
```
python ./src/tupan/manage.py spectacular --color --file schema.yml
```

### Como acessar o swagger
Rode a aplicação e acesse o endpoint:
> /api/schema/swagger-ui

## Testes

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ python-dotenv==1.0.1
sqlparse==0.5.1
typing_extensions==4.12.2
tzdata==2024.1
drf-spectacular
12 changes: 12 additions & 0 deletions src/tupan/tupan/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,20 @@
'rest_framework',
'alertas',
'estacoes'
'drf_spectacular',
]

REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}

SPECTACULAR_SETTINGS = {
'TITLE': 'Tupã API',
'DESCRIPTION': '',
'VERSION': '1.0.0',
'SERVE_INCLUDE_SCHEMA': False,
}

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand Down
7 changes: 6 additions & 1 deletion src/tupan/tupan/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
"""
from django.contrib import admin
from django.urls import include, path
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('estacoes.urls'))
path('', include('estacoes.urls')),
path('admin/', admin.site.urls),
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
]