From 66086cf2d18ca007224a79269efdfa74f1a035e1 Mon Sep 17 00:00:00 2001 From: "T. Franzel" Date: Sun, 19 Dec 2021 20:05:30 +0100 Subject: [PATCH] add root level extension setting #619 --- drf_spectacular/plumbing.py | 3 ++- drf_spectacular/settings.py | 4 ++++ tests/test_specification_extensions.py | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drf_spectacular/plumbing.py b/drf_spectacular/plumbing.py index ae151cd8..319882b1 100644 --- a/drf_spectacular/plumbing.py +++ b/drf_spectacular/plumbing.py @@ -410,7 +410,8 @@ def build_root_object(paths, components, version): **settings.EXTENSIONS_INFO, }, 'paths': {**paths, **settings.APPEND_PATHS}, - 'components': components + 'components': components, + **settings.EXTENSIONS_ROOT, } if settings.DESCRIPTION: root['info']['description'] = settings.DESCRIPTION diff --git a/drf_spectacular/settings.py b/drf_spectacular/settings.py index 8e6996de..fd43f53f 100644 --- a/drf_spectacular/settings.py +++ b/drf_spectacular/settings.py @@ -183,6 +183,10 @@ # https://swagger.io/specification/#specification-extensions 'EXTENSIONS_INFO': {}, + # Arbitrary specification extensions attached to the schema's root object. + # https://swagger.io/specification/#specification-extensions + 'EXTENSIONS_ROOT': {}, + # Oauth2 related settings. used for example by django-oauth2-toolkit. # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#oauth-flows-object 'OAUTH2_FLOWS': [], diff --git a/tests/test_specification_extensions.py b/tests/test_specification_extensions.py index 5480b65c..eb828cda 100644 --- a/tests/test_specification_extensions.py +++ b/tests/test_specification_extensions.py @@ -17,6 +17,9 @@ 'url': 'https://www.django-rest-framework.org/img/logo.png', }, }) +@mock.patch('drf_spectacular.settings.spectacular_settings.EXTENSIONS_ROOT', { + 'x-tagGroups': [{'name': 'Foo', 'tags': ['bar', 'baz']}] +}) def test_root_info_spec_extensions(no_warnings): # https://redoc.ly/docs/api-reference-docs/specification-extensions/x-logo/ @@ -29,6 +32,7 @@ class XAPIView(APIView): 'backgroundColor': "#ffffff", 'url': 'https://www.django-rest-framework.org/img/logo.png', } + assert schema['x-tagGroups'] == [{'name': 'Foo', 'tags': ['bar', 'baz']}] def test_operation_spec_extensions(no_warnings):