Skip to content

Commit 38b4c23

Browse files
richmahntechknowlogick
authored andcommitted
Fixes #6659 - Swagger schemes selection default to page's (#6660)
1 parent 450fc9a commit 38b4c23

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

templates/swagger/ui.tmpl

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,33 @@
7171
<script>
7272

7373
window.onload = function() {
74-
// Build a system
75-
const ui = SwaggerUIBundle({
76-
url: "{{AppUrl}}swagger.{{.APIJSONVersion}}.json",
77-
dom_id: '#swagger-ui',
78-
deepLinking: true,
79-
presets: [
80-
SwaggerUIBundle.presets.apis,
81-
SwaggerUIStandalonePreset
82-
],
83-
plugins: [
84-
SwaggerUIBundle.plugins.DownloadUrl
85-
],
86-
layout: "StandaloneLayout"
87-
})
74+
// Fetch the Swagger JSON specs
75+
var url = "{{AppUrl}}swagger.{{.APIJSONVersion}}.json"
76+
fetch(url)
77+
.then(function(response) {
78+
response.json()
79+
.then(function(spec) {
80+
// Make the page's protocol be at the top of the schemes list
81+
var protocol = window.location.protocol.slice(0, -1)
82+
spec.schemes.sort(function(x,y){ return x == protocol ? -1 : y == protocol ? 1 : 0 })
83+
// Build the Swagger UI
84+
const ui = SwaggerUIBundle({
85+
spec: spec,
86+
dom_id: '#swagger-ui',
87+
deepLinking: true,
88+
presets: [
89+
SwaggerUIBundle.presets.apis,
90+
SwaggerUIStandalonePreset
91+
],
92+
plugins: [
93+
SwaggerUIBundle.plugins.DownloadUrl
94+
],
95+
layout: "StandaloneLayout"
96+
})
8897

89-
window.ui = ui
98+
window.ui = ui
99+
})
100+
})
90101
}
91102
</script>
92103
</body>

0 commit comments

Comments
 (0)