diff --git a/docs/ui.go b/docs/ui.go new file mode 100644 index 0000000..46ae952 --- /dev/null +++ b/docs/ui.go @@ -0,0 +1,68 @@ +package docs + +import "github.com/gin-gonic/gin" + +var ui = ` + + + + + + Swagger UI + + + + + + + +
+ + + + + + +` + +// UI serves the swagger ui. +func UI(ctx *gin.Context) { + ctx.Writer.WriteString(ui) +} diff --git a/docs/ui_test.go b/docs/ui_test.go new file mode 100644 index 0000000..418a676 --- /dev/null +++ b/docs/ui_test.go @@ -0,0 +1,24 @@ +package docs + +import ( + "net/http/httptest" + "testing" + + "github.com/gin-gonic/gin" + "github.com/gotify/server/mode" + "github.com/stretchr/testify/assert" +) + +func TestUI(t *testing.T) { + mode.Set(mode.TestDev) + recorder := httptest.NewRecorder() + ctx, _ := gin.CreateTestContext(recorder) + withURL(ctx, "http", "example.com") + + ctx.Request = httptest.NewRequest("GET", "/swagger", nil) + + UI(ctx) + + content := recorder.Body.String() + assert.NotEmpty(t, content) +} diff --git a/go.mod b/go.mod index 73b6a37..99b930e 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( github.com/jinzhu/gorm v1.9.2 github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a // indirect github.com/jinzhu/now v0.0.0-20181116074157-8ec929ed50c3 // indirect - github.com/jmattheis/go-packr-swagger-ui v3.20.5+incompatible github.com/json-iterator/go v1.1.5 // indirect github.com/lib/pq v1.0.0 // indirect github.com/mattn/go-isatty v0.0.4 // indirect diff --git a/go.sum b/go.sum index e0deae1..88dd655 100644 --- a/go.sum +++ b/go.sum @@ -224,8 +224,6 @@ github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a h1:eeaG9XMUvRBYX github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v0.0.0-20181116074157-8ec929ed50c3 h1:xvj06l8iSwiWpYgm8MbPp+naBg+pwfqmdXabzqPCn/8= github.com/jinzhu/now v0.0.0-20181116074157-8ec929ed50c3/go.mod h1:oHTiXerJ20+SfYcrdlBO7rzZRJWGwSTQ0iUY2jI6Gfc= -github.com/jmattheis/go-packr-swagger-ui v3.20.5+incompatible h1:LgKnUch72aFvs27+ZRkmRZ6446gyAdcFMu4KwCsx9/4= -github.com/jmattheis/go-packr-swagger-ui v3.20.5+incompatible/go.mod h1:hDVllOsf5pUHlQ31WNgC4Zqm34JjPAFRogNa8+pFGLU= github.com/jmoiron/sqlx v0.0.0-20180614180643-0dae4fefe7c0/go.mod h1:IiEW3SEiiErVyFdH8NTuWjSifiEQKUoyK3LNqr2kCHU= github.com/joho/godotenv v1.2.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= diff --git a/router/router.go b/router/router.go index 706b0f1..5a56fff 100644 --- a/router/router.go +++ b/router/router.go @@ -1,7 +1,6 @@ package router import ( - "net/http" "time" "github.com/gin-gonic/gin" @@ -16,7 +15,6 @@ import ( "github.com/gotify/server/mode" "github.com/gotify/server/model" "github.com/gotify/server/ui" - "github.com/jmattheis/go-packr-swagger-ui" ) // Create creates the gin engine with all routes. @@ -44,7 +42,7 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co g.GET("/swagger", docs.Serve) g.Static("/image", conf.UploadedImagesDir) - g.GET("/docs/*any", gin.WrapH(http.StripPrefix("/docs/", http.FileServer(swaggerui.GetBox())))) + g.GET("/docs", docs.UI) g.Use(func(ctx *gin.Context) { ctx.Header("Content-Type", "application/json")