Repository: swaggest/rest (go)

Issue:
Content Type application/json should not have a charset attribute
**Describe the bug**
According to https://github.com/go-chi/chi/issues/194 `; charset=utf-8` should be removed from

https://github.com/swaggest/rest/blob/master/response/encoder.go#L143
https://github.com/swaggest/rest/blob/master/response/encoder.go#L199




Pull request:
Remove charset attribute from JSON content type
Resolves #113.

Patch:
diff --git a/openapi/collector.go b/openapi/collector.go
index 6b0574e..08d4a60 100644
--- a/openapi/collector.go
+++ b/openapi/collector.go
@@ -546,7 +546,7 @@ func (c *Collector) ServeHTTP(rw http.ResponseWriter, _ *http.Request) {
 		http.Error(rw, err.Error(), http.StatusInternalServerError)
 	}
 
-	rw.Header().Set("Content-Type", "application/json; charset=utf8")
+	rw.Header().Set("Content-Type", "application/json")
 
 	_, err = rw.Write(document)
 	if err != nil {
diff --git a/response/encoder.go b/response/encoder.go
index 64282d1..32ef032 100644
--- a/response/encoder.go
+++ b/response/encoder.go
@@ -33,11 +33,11 @@ type noContent interface {
 
 // DefaultSuccessResponseContentType is a package-level variable set to
 // default success response content type.
-var DefaultSuccessResponseContentType = "application/json; charset=utf-8"
+var DefaultSuccessResponseContentType = "application/json"
 
 // DefaultErrorResponseContentType is a package-level variable set to
 // default error response content type.
-var DefaultErrorResponseContentType = "application/json; charset=utf-8"
+var DefaultErrorResponseContentType = "application/json"
 
 // addressable makes a pointer from a non-pointer values.
 func addressable(output interface{}) interface{} {


Test patch:
diff --git a/_examples/advanced/validation_test.go b/_examples/advanced/validation_test.go
index 437372e..7c8865b 100644
--- a/_examples/advanced/validation_test.go
+++ b/_examples/advanced/validation_test.go
@@ -65,7 +65,7 @@ func TestNewRouter_validation(t *testing.T) {
 		r.ServeHTTP(rw, req)
 
 		assert.Equal(t, http.StatusBadRequest, rw.Code)
-		assert.Equal(t, "application/json; charset=utf-8", rw.Header().Get("Content-Type"))
+		assert.Equal(t, "application/json", rw.Header().Get("Content-Type"))
 		assertjson.EqualMarshal(t, []byte(`{
 		  "msg":"invalid argument: validation failed",
 		  "details":{"header:X-Input":["#: must be \u003e= 10/1 but found 5"]}
@@ -84,7 +84,7 @@ func TestNewRouter_validation(t *testing.T) {
 		r.ServeHTTP(rw, req)
 
 		assert.Equal(t, http.StatusBadRequest, rw.Code)
-		assert.Equal(t, "application/json; charset=utf-8", rw.Header().Get("Content-Type"))
+		assert.Equal(t, "application/json", rw.Header().Get("Content-Type"))
 		assertjson.EqualMarshal(t, []byte(`{
 		  "msg":"invalid argument: validation failed",
 		  "details":{"body":["#/data/value: length must be \u003e= 3, but got 1"]}
@@ -103,7 +103,7 @@ func TestNewRouter_validation(t *testing.T) {
 		r.ServeHTTP(rw, req)
 
 		assert.Equal(t, http.StatusInternalServerError, rw.Code)
-		assert.Equal(t, "application/json; charset=utf-8", rw.Header().Get("Content-Type"))
+		assert.Equal(t, "application/json", rw.Header().Get("Content-Type"))
 		assertjson.EqualMarshal(t, []byte(`{
 		  "msg":"internal: bad response: validation failed",
 		  "details":{"header:X-Output":["#: must be \u003c= 20/1 but found 45"]}
@@ -121,7 +121,7 @@ func TestNewRouter_validation(t *testing.T) {
 		r.ServeHTTP(rw, req)
 
 		assert.Equal(t, http.StatusInternalServerError, rw.Code)
-		assert.Equal(t, "application/json; charset=utf-8", rw.Header().Get("Content-Type"))
+		assert.Equal(t, "application/json", rw.Header().Get("Content-Type"))
 		assertjson.EqualMarshal(t, []byte(`{
 		  "msg":"internal: bad response: validation failed",
 		  "details":{"body":["#/data/value: length must be \u003c= 7, but got 10"]}
diff --git a/response/encoder_test.go b/response/encoder_test.go
index 704d356..5a1d1c6 100644
--- a/response/encoder_test.go
+++ b/response/encoder_test.go
@@ -61,7 +61,7 @@ func TestEncoder_SetupOutput(t *testing.T) {
 		ErrorText: "failed",
 	})
 	assert.Equal(t, http.StatusExpectationFailed, w.Code)
-	assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
+	assert.Equal(t, "application/json", w.Header().Get("Content-Type"))
 	assert.Equal(t, "19", w.Header().Get("Content-Length"))
 	assert.Equal(t, `{"error":"failed"}`+"\n", w.Body.String())
 
@@ -70,7 +70,7 @@ func TestEncoder_SetupOutput(t *testing.T) {
 	e.WriteSuccessfulResponse(w, r, output, ht)
 	assert.Equal(t, http.StatusInternalServerError, w.Code)
 	assert.Equal(t, "", w.Header().Get("X-Name"))
-	assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
+	assert.Equal(t, "application/json", w.Header().Get("Content-Type"))
 	assert.Equal(t, "140", w.Header().Get("Content-Length"))
 	assert.Equal(t, `{"status":"INTERNAL","error":"internal: bad response: validation failed",`+
 		`"context":{"header:X-Name":["#: length must be >= 3, but got 2"]}}`+"\n", w.Body.String())