Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Set up Go
uses: actions/setup-go@v1
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
- name: test
Expand Down
6 changes: 6 additions & 0 deletions swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ func CustomWrapHandler(config *Config, handler *webdav.Handler) gin.HandlerFunc
var matcher = regexp.MustCompile(`(.*)(index\.html|index\.css|swagger-initializer\.js|doc\.json|favicon-16x16\.png|favicon-32x32\.png|/oauth2-redirect\.html|swagger-ui\.css|swagger-ui\.css\.map|swagger-ui\.js|swagger-ui\.js\.map|swagger-ui-bundle\.js|swagger-ui-bundle\.js\.map|swagger-ui-standalone-preset\.js|swagger-ui-standalone-preset\.js\.map)[?|.]*`)

return func(ctx *gin.Context) {
// Return index.html content for /swagger or /swagger/
if ctx.Request.Method == http.MethodGet && (ctx.Request.RequestURI == "/swagger" || ctx.Request.RequestURI == "/swagger/") {
ctx.Header("Content-Type", "text/html; charset=utf-8")
_ = index.Execute(ctx.Writer, config.toSwaggerConfig())
return
}
if ctx.Request.Method != http.MethodGet {
ctx.AbortWithStatus(http.StatusMethodNotAllowed)

Expand Down
10 changes: 10 additions & 0 deletions swagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ func TestWrapCustomHandler(t *testing.T) {
assert.Equal(t, http.StatusMethodNotAllowed, performRequest(http.MethodPost, "/index.html", router).Code)

assert.Equal(t, http.StatusMethodNotAllowed, performRequest(http.MethodPut, "/index.html", router).Code)

// Test: /swagger should redirect to /swagger/index.html (not implemented yet, should fail)
w := performRequest(http.MethodGet, "/swagger", router)
assert.Equal(t, http.StatusOK, w.Code)
assert.Contains(t, w.Body.String(), "<title>Swagger UI</title>")

// Test: /swagger/ should also return index.html
wSlash := performRequest(http.MethodGet, "/swagger/", router)
assert.Equal(t, http.StatusOK, wSlash.Code)
assert.Contains(t, wSlash.Body.String(), "<title>Swagger UI</title>")
}

func TestDisablingWrapHandler(t *testing.T) {
Expand Down