diff --git a/assets.go b/assets.go index d0b488d..731c455 100644 --- a/assets.go +++ b/assets.go @@ -1,7 +1,7 @@ package echoswagger // CDN refer to https://www.jsdelivr.com/package/npm/swagger-ui-dist -const DefaultCDN = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@3.18.3" +const DefaultCDN = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@3.18.3-republish2" const SwaggerUIContent = `{{define "swagger"}} diff --git a/internal.go b/internal.go index 5242158..f31db99 100644 --- a/internal.go +++ b/internal.go @@ -36,13 +36,11 @@ func (r *Root) docHandler(swaggerPath string) echo.HandlerFunc { if err != nil { panic(err) } - - cdn := DefaultCDN - if r.ui.CDN != "" { - cdn = r.ui.CDN - } - return func(c echo.Context) error { + cdn := DefaultCDN + if r.ui.CDN != "" { + cdn = r.ui.CDN + } buf := new(bytes.Buffer) t.Execute(buf, map[string]interface{}{ "title": r.spec.Info.Title, diff --git a/wrapper_test.go b/wrapper_test.go index 0617852..3cfc273 100644 --- a/wrapper_test.go +++ b/wrapper_test.go @@ -293,17 +293,18 @@ func TestAddResponse(t *testing.T) { func TestUI(t *testing.T) { r := New(echo.New(), "/", "doc/", nil) - cdn := "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.18.1" - r.SetUI(UISetting{ - HideTop: true, - CDN: cdn, - }) se := r.(*Root) req := httptest.NewRequest(echo.GET, "/doc/", nil) rec := httptest.NewRecorder() c := se.echo.NewContext(req, rec) - h := se.docHandler("/doc/swagger.json") + + cdn := "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.18.0" + r.SetUI(UISetting{ + HideTop: true, + CDN: cdn, + }) + if assert.NoError(t, h(c)) { assert.Equal(t, http.StatusOK, rec.Code) assert.Contains(t, rec.Body.String(), cdn)