Skip to content

Commit

Permalink
Add custom Swagger UI intro
Browse files Browse the repository at this point in the history
  • Loading branch information
zamuzakki committed Sep 7, 2023
1 parent 4023d88 commit 638face
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ devweb-shell:
@echo "------------------------------------------------------------------"
@docker-compose exec dev /bin/bash

run-local:
@echo
@echo "------------------------------------------------------------------"
@echo "Running Django in development mode"
@echo "------------------------------------------------------------------"
@docker-compose exec dev python manage.py runserver 0.0.0.0:8080 --settings=core.settings.dev

db-bash:
@echo
@echo "------------------------------------------------------------------"
Expand Down
5 changes: 5 additions & 0 deletions django_project/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class SitePreferencesAdmin(admin.ModelAdmin):
'base_url_help_page',
)
}),
('Swagger UI', {
'fields': (
'swagger_ui_info',
)
})
)
inlines = (SitePreferencesImageInline,)

Expand Down
7 changes: 7 additions & 0 deletions django_project/core/models/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ class SitePreferences(SingletonModel):
)
)

swagger_ui_info = models.TextField(
default='',
help_text=_(
'Shown as the introduction at the top of Swagger UI. HTML and Markdown supported.'
)
)

class Meta: # noqa: D106
verbose_name_plural = "site preferences"

Expand Down
8 changes: 1 addition & 7 deletions django_project/core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,5 @@
SWAGGER_SETTINGS = {
'TAGS_SORTER': 'alpha',
'showCommonExtensions': 'true',
'SECURITY_DEFINITIONS': {
'ApiKey Auth': {
'type': 'apiKey',
'in': 'header',
'name': 'Authorization'
}
},
'SECURITY_DEFINITIONS': {},
}
7 changes: 0 additions & 7 deletions django_project/core/settings/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,6 @@
# override logout url in swagger ui
SWAGGER_SETTINGS['LOGIN_URL'] = '/azure-auth/login'
SWAGGER_SETTINGS['LOGOUT_URL'] = '/azure-auth/logout'
SWAGGER_SETTINGS['SECURITY_DEFINITIONS'].update({
'B2C JWT Token Auth': {
'type': 'apiKey',
'in': 'header',
'name': 'Authorization'
}
})
# Azure blob storage
AZURE_STORAGE = os.environ.get('AZURE_STORAGE')
AZURE_STORAGE_CONTAINER = os.environ.get('AZURE_STORAGE_CONTAINER')
Expand Down
2 changes: 2 additions & 0 deletions django_project/core/templates/drf-yasg/swagger-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
buttonTextEl.innerText = "Home";
buttonTextEl.style = "background-color: #49cc90;color: white; text-decoration: none; margin-bottom: 20px;position: absolute;margin-top: -40px;"
document.querySelector('.information-container').appendChild(buttonTextEl);

document.querySelector('hgroup.main').querySelector('a.link').innerHTML = ''
}
}, 100);
</script>
Expand Down
2 changes: 2 additions & 0 deletions django_project/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.conf.urls.static import static
from django.contrib import admin
from django.http import HttpResponseNotFound
from core.models.preferences import SitePreferences
import json


Expand Down Expand Up @@ -41,6 +42,7 @@ def get_context_data(self, **kwargs):
openapi.Info(
title="GeoRepo API",
default_version='v1.0.0',
description=SitePreferences.preferences().swagger_ui_info,
),
public=True,
permission_classes=[permissions.AllowAny],
Expand Down

0 comments on commit 638face

Please sign in to comment.