Merge pull request #6 from elvinchan/5
#5 Fix SetUI not work bug & CDN address
This commit is contained in:
commit
e37e18e720
@ -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"}}
|
||||
<!DOCTYPE html>
|
||||
|
10
internal.go
10
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,
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user