Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func Handler(configFns ...func(*Config)) http.HandlerFunc {

// create a template with name
index, _ := template.New("swagger_index.html").Parse(indexTempl)
confScript, _ := template.New("swagger-ui-conf.js").Parse(scriptTempl)

re := regexp.MustCompile(`^(.*/)([^?].*)?[?|.]*$`)

Expand Down Expand Up @@ -212,6 +213,8 @@ func Handler(configFns ...func(*Config)) http.HandlerFunc {
switch path {
case "index.html":
_ = index.Execute(w, config)
case "swagger-ui-conf.js":
_ = confScript.Execute(w, config)
case "doc.json":
doc, err := swag.ReadDoc(config.InstanceName)
if err != nil {
Expand Down Expand Up @@ -304,7 +307,13 @@ const indexTempl = `<!-- HTML for static distribution bundle build -->

<script src="./swagger-ui-bundle.js"> </script>
<script src="./swagger-ui-standalone-preset.js"> </script>
<script>
<script src="./swagger-ui-conf.js"> </script>
</body>

</html>
`

const scriptTempl = `
window.onload = function() {
{{- if .BeforeScript}}
{{.BeforeScript}}
Expand Down Expand Up @@ -340,8 +349,4 @@ window.onload = function() {
{{.AfterScript}}
{{- end}}
}
</script>
</body>

</html>
`