Skip to content

Commit

Permalink
Fix handling of absolute schema URLs (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Sep 26, 2023
1 parent aed7778 commit 3379454
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,22 @@ import (
)

func main() {
http.Handle("/", v5emb.NewHandler("My API", "/swagger.json", "/"))
_ = http.ListenAndServe(":8080", nil)
http.Handle("/api1/docs/", v5emb.New(
"Petstore",
"https://petstore3.swagger.io/api/v3/openapi.json",
"/api1/docs/",
))

http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
_, _ = writer.Write([]byte("Hello World!"))
})

println("docs at http://localhost:8080/api1/docs/")
_ = http.ListenAndServe("localhost:8080", http.DefaultServeMux)
}
```


If you use `go1.16` or later, you can import natively embedded assets with `"github.com/swaggest/swgui/v5emb"`, it may
help to lower application memory usage.

Expand Down
5 changes: 4 additions & 1 deletion internal/index.tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ func IndexTpl(assetsBase, faviconBase string, cfg swgui.Config) string {
<script>
window.onload = function () {
var cfg = {{ .ConfigJson }};
var url = window.location.protocol + "//" + window.location.host + cfg.swaggerJsonUrl;
var url = cfg.swaggerJsonUrl;
if (!url.startsWith("https://") && !url.startsWith("http://")) {
url = window.location.protocol + "//" + window.location.host + url;
}
// Build a system
var settings = {
Expand Down

0 comments on commit 3379454

Please sign in to comment.