-
Notifications
You must be signed in to change notification settings - Fork 265
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
Feature Request: Optionally allow SwaggerUI Top Bar #483
Comments
With release 0.18.0 that now allows raw JS in the SWAGGER_UI_SETTINGS, I was able to use the following settings to add the topbar: 'SWAGGER_UI_SETTINGS': '''{
deepLinking: true,
urls: [{url: "/api/schema-v1/", name: "v1"}, {url: "/api/schema-v2/", name: "v2"}],
presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
layout: "StandaloneLayout",
}''', I created my own template to load in the necessary script, taking advantage of django's <script src="{{dist}}/swagger-ui-standalone-preset.js"></script>
{% include "drf_spectacular/swagger_ui.html" %} I then created my own version of SpectacularSwaggerView as follows: from drf_spectacular.views import SpectacularSwaggerView
class SpectacularSwaggerViewTopBar(SpectacularSwaggerView):
template_name = 'drf_spectacular_mod/swagger_ui.html' # path to my customized swaggerui html template This is a pretty simple customization and I was able to mostly rely on the package for it, but having |
Hi @ahebard, thanks for that detailed report. I'm not expert on Swagger and so i never 100% understood what I have no concerns adding do you have more insight into what the impact could be? |
added a convenient way to version
this should already be possible via the default DRF override idiom. path('api/v2/schema/', SpectacularAPIView.as_view(template_name='drf_spectacular_mod/swagger_ui.html'), name='schema'), that shouldn't be necessart anymore, because i also decided to include |
closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up. |
WHY:
It would be useful to have the optional ability to use the SwaggerUI Top Bar, which includes a dropdown for which schema to view. This dropdown is particularly useful for api's with different versions, the user can clearly see that there are different versions without having to navigate to any other page.
HOW:
This could be accomplished by adding a
SWAGGER_UI_USE_TOP_BAR
setting that gets passed from the SwaggerUI views into the html and js templates. In this example implementation, the html SwaggerUI template optionally loadsswagger-ui-standalone-preset.js
based on the value ofuse_topbar
. The SwaggerUI js template optionally addsSwaggerUIStandalonePreset
to the presets based on the value ofuse_topbar
and optionally uses StandaloneLayout instead of BaseLayout based onuse_topbar
.Below are copies of the full content of the 4 relevant files with the (small) changes described.
The text was updated successfully, but these errors were encountered: