Skip to content

Commit

Permalink
add root level extension setting #619
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Dec 19, 2021
1 parent 428282c commit 66086cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drf_spectacular/plumbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions drf_spectacular/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [],
Expand Down
4 changes: 4 additions & 0 deletions tests/test_specification_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand All @@ -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):
Expand Down

0 comments on commit 66086cf

Please sign in to comment.