diff options
author | Richard Mahn <richmahn@users.noreply.github.com> | 2019-04-16 16:09:36 -0600 |
---|---|---|
committer | techknowlogick <matti@mdranta.net> | 2019-04-16 18:09:36 -0400 |
commit | 38b4c23d2481da49e0138eba2cfb3e9410b4565b (patch) | |
tree | 65ba8a5cb6be76bb435ed47a568cb0795fb3cd8f /templates/swagger | |
parent | 450fc9a12015317eaafd1876932bd358fad4054a (diff) | |
download | gitea-38b4c23d2481da49e0138eba2cfb3e9410b4565b.tar.gz gitea-38b4c23d2481da49e0138eba2cfb3e9410b4565b.zip |
Fixes #6659 - Swagger schemes selection default to page's (#6660)
Diffstat (limited to 'templates/swagger')
-rw-r--r-- | templates/swagger/ui.tmpl | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/templates/swagger/ui.tmpl b/templates/swagger/ui.tmpl index d3ef2beb23..802ce70eac 100644 --- a/templates/swagger/ui.tmpl +++ b/templates/swagger/ui.tmpl @@ -71,22 +71,33 @@ <script> window.onload = function() { - // Build a system - const ui = SwaggerUIBundle({ - url: "{{AppUrl}}swagger.{{.APIJSONVersion}}.json", - dom_id: '#swagger-ui', - deepLinking: true, - presets: [ - SwaggerUIBundle.presets.apis, - SwaggerUIStandalonePreset - ], - plugins: [ - SwaggerUIBundle.plugins.DownloadUrl - ], - layout: "StandaloneLayout" - }) + // Fetch the Swagger JSON specs + var url = "{{AppUrl}}swagger.{{.APIJSONVersion}}.json" + fetch(url) + .then(function(response) { + response.json() + .then(function(spec) { + // Make the page's protocol be at the top of the schemes list + var protocol = window.location.protocol.slice(0, -1) + spec.schemes.sort(function(x,y){ return x == protocol ? -1 : y == protocol ? 1 : 0 }) + // Build the Swagger UI + const ui = SwaggerUIBundle({ + spec: spec, + dom_id: '#swagger-ui', + deepLinking: true, + presets: [ + SwaggerUIBundle.presets.apis, + SwaggerUIStandalonePreset + ], + plugins: [ + SwaggerUIBundle.plugins.DownloadUrl + ], + layout: "StandaloneLayout" + }) - window.ui = ui + window.ui = ui + }) + }) } </script> </body> |