Skip to content
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

Add javascript hooks in UI init scripts #294

Open
oneandonlyonebutyou opened this issue Jan 17, 2019 · 5 comments
Open

Add javascript hooks in UI init scripts #294

oneandonlyonebutyou opened this issue Jan 17, 2019 · 5 comments
Labels
enhancement Enhancement proposal

Comments

@oneandonlyonebutyou
Copy link

I wonder how I could add configs to the swagger settings.
Thanks.
something like this :

swagger-api/swagger-ui#3229

  // Build a system
  const ui = SwaggerUIBundle({
    ...
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    presets_config: {
       SwaggerUIStandalonePreset: {
           TopbarPlugin: false
       }
    }
    ...
  })

  window.ui = ui
}
@axnsan12
Copy link
Owner

axnsan12 commented Jan 18, 2019

You can always deploy your own swagger-ui instance instead of using the bundled one.

Unfortunately no, there is no simple way to plug that into the bundled one.

@oneandonlyonebutyou
Copy link
Author

Thanks for fast response. (means a lot)
I would love to contribute soon ..

@axnsan12 axnsan12 added the enhancement Enhancement proposal label Jan 29, 2019
@axnsan12 axnsan12 changed the title TopbarPlugin: false to remove the top bar Add javascript hooks in UI init scripts Jan 29, 2019
@rsichnyi
Copy link
Contributor

@joseph-vedadi this is a bit hacky, but what you could do is:

  1. add your own template (drf-yasg.html):
{% extends "drf-yasg/swagger-ui.html" %}

{% block extra_scripts %}
<script>
  swaggerUiConfig.layout = "BaseLayout";
  // any other override you'd like to do
</script>
{% endblock %}
  1. change your urls.py:
from drf_yasg.views import SwaggerUIRenderer, get_schema_view

SwaggerUIRenderer.template = 'drf-yasg.html'  # monkey-patching is bad :(

schema_view = get_schema_view(
    openapi.Info(
        title="My API",
        default_version='1.0.0',
        description="My API"
    )
)

@axnsan12
Copy link
Owner

Monkey patching shouldn't be necessary, the template can be overridden using the standard Django mechanism - place it at the same path drf-yasg/swagger-ui.html in the templates directory of an app.

The app should come before drf-yasg in INSTALLED_APPS.

@rsichnyi
Copy link
Contributor

@axnsan12 iirc in that case {% extends "drf-yasg/swagger-ui.html" %} will fail because it'll become cyclic dependency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement proposal
Projects
None yet
Development

No branches or pull requests

3 participants