-
Notifications
You must be signed in to change notification settings - Fork 515
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
Added configuration for swagger-ui and jquery js external-load URLs. #245
Conversation
…d URLs. This change allows new Flasgger config keys to specify the URL location where jQuery and Swagger javascript sources, and Swagger CSS are loaded from, allowing them to be loaded from Flasgger's static copies (default), or any URL, including hosted sources. This can allow any compatible version of those libraries to be loaded, allowing the latest Swagger UI to be loaded by Flasgger templates. The new, optional config keys are: - swagger_ui_bundle_js - swagger_ui_standalone_preset_js - jquery_js - swagger_ui_css For example, the following can be used to load scripts from unpkg.com: app = Flask(__name__) app.config['SWAGGER'] = { 'title': 'Colors API' } swagger_config = Swagger.DEFAULT_CONFIG swagger_config['swagger_ui_bundle_js'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js' swagger_config['swagger_ui_standalone_preset_js'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js' swagger_config['jquery_js'] = '//unpkg.com/jquery@2.2.4/dist/jquery.min.js' swagger_config['swagger_ui_css'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui.css' Swagger(app, config=swagger_config) As part of this change, template part flasgger/body_scripts.html was factored-out of index.html, making it easier to override and replace the body script load section entirely if desired. Added a test/example.
265b3cd
to
1467de3
Compare
This
I think the only ways are using the scripts + config variables, which is already in place, I cannot think of anything different than that. (for more customization, users will need to rewrite the whole template) |
@rochacbruno thanks for the review. I'm good with the colors example for now, and the variables seem OK too. Let me know if you have any changes or will review further or are +ve or -ve on this sort of change. I think it should make it fairly easy for flasgger users to choose updated Swagger UI versions. |
@javabrett LGTM |
For anyone interested, there's now a live example of this deployed to http://flasgger.pythonanywhere.com/colors_external_js/apidocs/ . This loads the latest Swagger UI 3.x into Flasgger's UI, which at the time of this post is 3.19.5. |
This change allows new Flasgger config keys to specify the URL location where Swagger UI and jQuery javascript sources are loaded from, allowing them to be loaded from Flasgger's static copies (default), or any URL, including hosted sources. This can allow any compatible version of those libraries to be loaded, allowing the latest Swagger UI to be loaded by Flasgger templates.
The new, optional config keys are:
For example, the following can be used to load scripts from unpkg.com:
As part of this change, template part flasgger/body_scripts.html was factored-out of index.html, making it easier to override and replace the body script load section entirely if desired.
Added a test/example.
This is somewhat inspired by discussions in #231, so I mention it here.
Questions
body_scripts.html
template.url
in them.Testing
colors_external_js
example with a browser in developer mode and note where the scripts are fetched from. The example is using a floating/latest ui3 mechanism, so there is a redirect involved. This loads the latest Swagger UI 3.x, which currently loads 3.19.0.TODO
I notice I need to externalise the CSS link too.