diff --git a/swagger.go b/swagger.go index 7e0e414..3888ede 100644 --- a/swagger.go +++ b/swagger.go @@ -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) diff --git a/swagger_test.go b/swagger_test.go index 85c5cb7..f3a3b95 100644 --- a/swagger_test.go +++ b/swagger_test.go @@ -80,6 +80,11 @@ 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(), "