Skip to content

Commit

Permalink
Fixes go-gitea#6659 - Swagger schemes selection default to page's
Browse files Browse the repository at this point in the history
  • Loading branch information
richmahn committed Apr 16, 2019
1 parent 8d01b98 commit b058b0a
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions templates/swagger/ui.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit b058b0a

Please sign in to comment.