mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
utilities: add converters module and use for json/yaml url
This commit is contained in:
parent
f9cd89a4a4
commit
b114b9d396
@ -1,14 +1,17 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls import include, url
|
from django.conf.urls import include
|
||||||
from django.urls import path
|
from django.urls import path, register_converter
|
||||||
from django.views.static import serve
|
from django.views.static import serve
|
||||||
from drf_yasg import openapi
|
from drf_yasg import openapi
|
||||||
from drf_yasg.views import get_schema_view
|
from drf_yasg.views import get_schema_view
|
||||||
|
|
||||||
from netbox.views import APIRootView, HomeView, SearchView
|
from netbox.views import APIRootView, HomeView, SearchView
|
||||||
from users.views import LoginView, LogoutView
|
from users.views import LoginView, LogoutView
|
||||||
|
from utilities import converters
|
||||||
from .admin import admin_site
|
from .admin import admin_site
|
||||||
|
|
||||||
|
register_converter(converters.JSONOrYAMLConverter, 'json_or_yaml')
|
||||||
|
|
||||||
schema_view = get_schema_view(
|
schema_view = get_schema_view(
|
||||||
openapi.Info(
|
openapi.Info(
|
||||||
title="NetBox API",
|
title="NetBox API",
|
||||||
@ -53,7 +56,7 @@ _patterns = [
|
|||||||
path(r'api/virtualization/', include('virtualization.api.urls')),
|
path(r'api/virtualization/', include('virtualization.api.urls')),
|
||||||
path(r'api/docs/', schema_view.with_ui('swagger'), name='api_docs'),
|
path(r'api/docs/', schema_view.with_ui('swagger'), name='api_docs'),
|
||||||
path(r'api/redoc/', schema_view.with_ui('redoc'), name='api_redocs'),
|
path(r'api/redoc/', schema_view.with_ui('redoc'), name='api_redocs'),
|
||||||
url(r'api/swagger(?P<format>.json|.yaml)', schema_view.without_ui(), name='schema_swagger'),
|
path(r'api/swagger<json_or_yaml:format>', schema_view.without_ui(), name='schema_swagger'),
|
||||||
|
|
||||||
# Serving static media in Django to pipe it through LoginRequiredMiddleware
|
# Serving static media in Django to pipe it through LoginRequiredMiddleware
|
||||||
path(r'media/<path:path>', serve, {'document_root': settings.MEDIA_ROOT}),
|
path(r'media/<path:path>', serve, {'document_root': settings.MEDIA_ROOT}),
|
||||||
|
8
netbox/utilities/converters.py
Normal file
8
netbox/utilities/converters.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class JSONOrYAMLConverter:
|
||||||
|
regex = '.json|.yaml'
|
||||||
|
|
||||||
|
def to_python(self, value):
|
||||||
|
return value
|
||||||
|
|
||||||
|
def to_url(self, value):
|
||||||
|
return value
|
Loading…
Reference in New Issue
Block a user