From 6322a8f7974f9b1848334ab2892d25e5cbbf6c51 Mon Sep 17 00:00:00 2001 From: singhwang Date: Thu, 12 Aug 2021 04:26:37 +0800 Subject: [PATCH] Solve the integration swagger into the gin framework, access the Chinese garbled problem in the json returned by swagger/doc.json. (#78) enable UTF8 for swagger json documentation --- swagger.go | 2 +- swagger_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/swagger.go b/swagger.go index b075403..1698cd1 100644 --- a/swagger.go +++ b/swagger.go @@ -85,7 +85,7 @@ func CustomWrapHandler(config *Config, h *webdav.Handler) gin.HandlerFunc { } else if strings.HasSuffix(path, ".js") { c.Header("Content-Type", "application/javascript") } else if strings.HasSuffix(path, ".json") { - c.Header("Content-Type", "application/json") + c.Header("Content-Type", "application/json; charset=utf-8") } switch path { diff --git a/swagger_test.go b/swagger_test.go index 693326c..694a84b 100644 --- a/swagger_test.go +++ b/swagger_test.go @@ -132,7 +132,7 @@ func TestWithGzipMiddleware(t *testing.T) { w4 := performRequest("GET", "/doc.json", router) assert.Equal(t, 200, w4.Code) - assert.Equal(t, w4.Header()["Content-Type"][0], "application/json") + assert.Equal(t, w4.Header()["Content-Type"][0], "application/json; charset=utf-8") } func performRequest(method, target string, router *gin.Engine) *httptest.ResponseRecorder {