diff --git a/doc/cookbook/custom-errors/CustomErrors.lhs b/doc/cookbook/custom-errors/CustomErrors.lhs index 2dee12b67..6d3ad1e14 100644 --- a/doc/cookbook/custom-errors/CustomErrors.lhs +++ b/doc/cookbook/custom-errors/CustomErrors.lhs @@ -176,7 +176,7 @@ Now if we try to request something with a wrong body, we will get a nice error: ``` $ http -j POST localhost:8000/greet 'foo=bar' HTTP/1.1 400 Bad Request -Content-Type: application/json;charset=utf-8 +Content-Type: application/json Date: Fri, 17 Jul 2020 13:34:18 GMT Server: Warp/3.3.12 Transfer-Encoding: chunked diff --git a/doc/cookbook/file-upload/FileUpload.lhs b/doc/cookbook/file-upload/FileUpload.lhs index a79849c53..aa3cbfe53 100644 --- a/doc/cookbook/file-upload/FileUpload.lhs +++ b/doc/cookbook/file-upload/FileUpload.lhs @@ -133,7 +133,7 @@ examples. [...] -Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Transfer-Encoding","chunked"),("Date","Fri, 08 Dec 2017 16:50:14 GMT"),("Server","Warp/3.2.13"),("Content-Type","application/json;charset=utf-8")], responseBody = "0", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose} +Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Transfer-Encoding","chunked"),("Date","Fri, 08 Dec 2017 16:50:14 GMT"),("Server","Warp/3.2.13"),("Content-Type","application/json")], responseBody = "0", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose} ``` As usual, the code for this recipe is available in a cabal project diff --git a/doc/cookbook/hoist-server-with-context/HoistServerWithContext.lhs b/doc/cookbook/hoist-server-with-context/HoistServerWithContext.lhs index 8d7366615..68b4a944f 100644 --- a/doc/cookbook/hoist-server-with-context/HoistServerWithContext.lhs +++ b/doc/cookbook/hoist-server-with-context/HoistServerWithContext.lhs @@ -378,7 +378,7 @@ $ curl -v -XPOST 'http://localhost:3001/login' \ < HTTP/1.1 200 OK ... < Server: Warp/3.2.25 -< Content-Type: application/json;charset=utf-8 +< Content-Type: application/json < Set-Cookie: JWT-Cookie=eyJhbGciOiJIUzUxMiJ9.eyJkYXQiOnsibmFtZSI6ImFkbWluIn19.SIoRcABKSO4mXnRifzqPWlHJUhVwuy32Qon7s1E_c3vHOsLXdXyX4V4eXOw9tMFoeIqgsXMZucqoFb36vAdKwQ; Path=/; HttpOnly; SameSite=Lax < Set-Cookie: XSRF-TOKEN=y5PmrYHX3ywFUCwGRQqHh1TDheTLiQpwRQB3FFRd8N4=; Path=/ ... diff --git a/doc/cookbook/multiverb/MultiVerb.lhs b/doc/cookbook/multiverb/MultiVerb.lhs index 840f6299b..c260d3874 100644 --- a/doc/cookbook/multiverb/MultiVerb.lhs +++ b/doc/cookbook/multiverb/MultiVerb.lhs @@ -164,7 +164,7 @@ Now let us run the server and observe how it behaves: ``` $ http http://localhost:5000/version HTTP/1.1 200 OK -Content-Type: application/json;charset=utf-8 +Content-Type: application/json Date: Thu, 29 Aug 2024 14:22:20 GMT Server: Warp/3.4.1 Transfer-Encoding: chunked @@ -176,7 +176,7 @@ Transfer-Encoding: chunked ``` $ http http://localhost:5000/choices/3 HTTP/1.1 200 OK -Content-Type: application/json;charset=utf-8 +Content-Type: application/json Date: Thu, 29 Aug 2024 14:22:30 GMT Server: Warp/3.4.1 Transfer-Encoding: chunked @@ -187,7 +187,7 @@ true ``` $ http http://localhost:5000/choices/2 HTTP/1.1 200 OK -Content-Type: application/json;charset=utf-8 +Content-Type: application/json Date: Thu, 29 Aug 2024 14:22:33 GMT Server: Warp/3.4.1 Transfer-Encoding: chunked diff --git a/doc/cookbook/openapi3/OpenAPI.lhs b/doc/cookbook/openapi3/OpenAPI.lhs index 01f55744f..0aaaf381a 100644 --- a/doc/cookbook/openapi3/OpenAPI.lhs +++ b/doc/cookbook/openapi3/OpenAPI.lhs @@ -106,7 +106,7 @@ The generated schema looks something like this: "responses": { "200": { "content": { - "application/json;charset=utf-8": { + "application/json": { "schema": { "items": { "$ref": "#/components/schemas/Todo" diff --git a/doc/cookbook/testing/Testing.lhs b/doc/cookbook/testing/Testing.lhs index 5dec8ec62..62c9540e2 100644 --- a/doc/cookbook/testing/Testing.lhs +++ b/doc/cookbook/testing/Testing.lhs @@ -467,7 +467,7 @@ Let's see what happens when we run these tests: Headers: "Transfer-Encoding": "chunked" "Date": "Fri, 12 Oct 2018 04:36:22 GMT" "Server": "Warp/3.2.25" - "Content-Type": "application/json;charset=utf-8" + "Content-Type": "application/json" Body: "" To rerun use: --match "/Main[339:25]/API demonstrates best practices/" diff --git a/doc/cookbook/using-free-client/UsingFreeClient.lhs b/doc/cookbook/using-free-client/UsingFreeClient.lhs index 80422456d..a643a7e36 100644 --- a/doc/cookbook/using-free-client/UsingFreeClient.lhs +++ b/doc/cookbook/using-free-client/UsingFreeClient.lhs @@ -163,7 +163,7 @@ Making request: Request { host = "localhost" port = 8000 secure = False - requestHeaders = [("Accept","application/json;charset=utf-8,application/json")] + requestHeaders = [("Accept","application/json")] path = "/square/42" queryString = "" method = "GET" @@ -181,7 +181,7 @@ Got response: Response [ ("Transfer-Encoding","chunked") , ("Date","Thu, 05 Jul 2018 21:12:41 GMT") , ("Server","Warp/3.2.22") - , ("Content-Type","application/json;charset=utf-8") + , ("Content-Type","application/json") ] , responseBody = "1764" , responseCookieJar = CJ {expose = []} diff --git a/doc/tutorial/Docs.lhs b/doc/tutorial/Docs.lhs index 1548ae36e..76bf6ae05 100644 --- a/doc/tutorial/Docs.lhs +++ b/doc/tutorial/Docs.lhs @@ -127,16 +127,16 @@ That lets us see what our API docs look like in markdown, by looking at `markdow - Supported content types are: - - `application/json;charset=utf-8` + - `application/json` - `application/json` -- When a value is provided for 'name' (`application/json;charset=utf-8`, `application/json`): +- When a value is provided for 'name' (`application/json`): ```json {"msg":"Hello, Alp"} ``` -- When 'name' is not specified (`application/json;charset=utf-8`, `application/json`): +- When 'name' is not specified (`application/json`): ```json {"msg":"Hello, anonymous coward"} @@ -148,10 +148,9 @@ That lets us see what our API docs look like in markdown, by looking at `markdow - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Example (`application/json`): ```json {"clientAge":26,"clientEmail":"alp@foo.com","clientName":"Alp","clientInterestedIn":["haskell","mathematics"]} @@ -164,10 +163,9 @@ That lets us see what our API docs look like in markdown, by looking at `markdow - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Example (`application/json`): ```json {"subject":"Hey Alp, we miss you!","body":"Hi Alp,\n\nSince you've recently turned 26, have you checked out our latest haskell, mathematics products? Give us a visit!","to":"alp@foo.com","from":"great@company.com"} @@ -187,10 +185,9 @@ That lets us see what our API docs look like in markdown, by looking at `markdow - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Example (`application/json`): ```json {"yCoord":14,"xCoord":3} @@ -236,11 +233,10 @@ The relevant output of `markdown api2Docs` is now: - Supported content types are: - - `application/json;charset=utf-8` - `application/json` - `application/x-www-form-urlencoded` -- Example (`application/json;charset=utf-8`, `application/json`): +- Example (`application/json`): ```json {"clientAge":26,"clientEmail":"alp@foo.com","clientName":"Alp","clientInterestedIn":["haskell","mathematics"]} diff --git a/servant-docs/example/greet.md b/servant-docs/example/greet.md index c4c983d7d..50db5bc7a 100644 --- a/servant-docs/example/greet.md +++ b/servant-docs/example/greet.md @@ -14,16 +14,15 @@ You'll also note that multiple intros are possible. - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- If you use ?capital=true (`application/json;charset=utf-8`, `application/json`): +- If you use ?capital=true (`application/json`): ```json "HELLO, HASKELLER" ``` -- If you use ?capital=false (`application/json;charset=utf-8`, `application/json`): +- If you use ?capital=false (`application/json`): ```json "Hello, haskeller" @@ -36,16 +35,15 @@ You'll also note that multiple intros are possible. - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- If you use ?capital=true (`application/json;charset=utf-8`, `application/json`): +- If you use ?capital=true (`application/json`): ```json "HELLO, HASKELLER" ``` -- If you use ?capital=false (`application/json;charset=utf-8`, `application/json`): +- If you use ?capital=false (`application/json`): ```json "Hello, haskeller" @@ -55,7 +53,7 @@ You'll also note that multiple intros are possible. ```bash curl -XPOST \ - -H "Content-Type: application/json;charset=utf-8" \ + -H "Content-Type: application/json" \ -d "\"HELLO, HASKELLER\"" \ http://localhost:80/greet ``` @@ -85,10 +83,9 @@ And some more - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Example (`application/json`): ```json @@ -126,17 +123,16 @@ curl -XDELETE \ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` - `text/plain;charset=utf-8` -- If you use ?capital=true (`application/json;charset=utf-8`, `application/json`, `text/plain;charset=utf-8`): +- If you use ?capital=true (`application/json`, `text/plain;charset=utf-8`): ```json "HELLO, HASKELLER" ``` -- If you use ?capital=false (`application/json;charset=utf-8`, `application/json`): +- If you use ?capital=false (`application/json`): ```json "Hello, haskeller" diff --git a/servant-docs/golden/comprehensive.md b/servant-docs/golden/comprehensive.md index e526100a5..b320289ab 100644 --- a/servant-docs/golden/comprehensive.md +++ b/servant-docs/golden/comprehensive.md @@ -7,10 +7,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -25,10 +24,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -43,10 +41,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -65,10 +62,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -87,10 +83,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -109,10 +104,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -130,10 +124,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -155,10 +148,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -173,10 +165,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -195,10 +186,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -213,10 +203,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json 17 @@ -235,10 +224,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -257,10 +245,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -275,10 +262,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -293,10 +279,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -311,10 +296,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -332,10 +316,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -357,10 +340,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -382,10 +364,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -408,10 +389,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -426,10 +406,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json 17 @@ -462,10 +441,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -477,10 +455,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Example (`application/json`): ```json 17 @@ -493,10 +470,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -508,10 +484,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Example (`application/json`): ```json 17 @@ -524,10 +499,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -542,10 +516,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -560,10 +533,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -575,7 +547,6 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` ### Response: @@ -585,7 +556,6 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` - No response body @@ -602,10 +572,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json @@ -620,10 +589,9 @@ - Supported content types are: - - `application/json;charset=utf-8` - `application/json` -- Example (`application/json;charset=utf-8`, `application/json`): +- Response body as below. ```json diff --git a/servant-server/test/Servant/ServerSpec.hs b/servant-server/test/Servant/ServerSpec.hs index f3b36bcdc..5916bcde5 100644 --- a/servant-server/test/Servant/ServerSpec.hs +++ b/servant-server/test/Servant/ServerSpec.hs @@ -288,7 +288,7 @@ verbSpec = describe "Servant.API.Verb" $ do response <- THW.request method "" [] "" liftIO $ simpleHeaders response - `shouldContain` [("Content-Type", "application/json;charset=utf-8")] + `shouldContain` [("Content-Type", "application/json")] it "works for Stream as for Result" $ do response <- THW.request method "/stream" [] "" @@ -752,7 +752,7 @@ reqBodySpec = describe "Servant.API.ReqBody" $ do THW.request method x - [(hContentType, "application/json;charset=utf-8")] + [(hContentType, "application/json")] with (pure $ serve reqBodyApi server) $ do it "passes the argument to the handler" $ do diff --git a/servant-swagger/example/swagger.json b/servant-swagger/example/swagger.json index 018bd8f57..f958822a3 100644 --- a/servant-swagger/example/swagger.json +++ b/servant-swagger/example/swagger.json @@ -56,7 +56,7 @@ } }, "produces": [ - "application/json;charset=utf-8" + "application/json" ], "parameters": [ { @@ -71,7 +71,7 @@ }, "put": { "consumes": [ - "application/json;charset=utf-8" + "application/json" ], "responses": { "400": { @@ -85,7 +85,7 @@ } }, "produces": [ - "application/json;charset=utf-8" + "application/json" ], "parameters": [ { @@ -110,7 +110,7 @@ "/todo": { "post": { "consumes": [ - "application/json;charset=utf-8" + "application/json" ], "responses": { "400": { @@ -124,7 +124,7 @@ } }, "produces": [ - "application/json;charset=utf-8" + "application/json" ], "parameters": [ { @@ -150,7 +150,7 @@ } }, "produces": [ - "application/json;charset=utf-8" + "application/json" ] } } diff --git a/servant-swagger/src/Servant/Swagger.hs b/servant-swagger/src/Servant/Swagger.hs index 3acd85320..2913d5482 100644 --- a/servant-swagger/src/Servant/Swagger.hs +++ b/servant-swagger/src/Servant/Swagger.hs @@ -104,7 +104,7 @@ import Servant.Swagger.Test -- In order to generate @'Swagger'@ specification for a servant API, just use @'toSwagger'@: -- -- >>> BSL8.putStrLn . orderedKeys $ toSwagger (Proxy :: Proxy UserAPI) --- {"definitions":{"User":{"properties":{"age":{"maximum":9223372036854775807,"minimum":-9223372036854775808,"type":"integer"},"name":{"type":"string"}},"required":["name","age"],"type":"object"},"UserId":{"type":"integer"}},"info":{"title":"","version":""},"paths":{"/":{"get":{"produces":["application/json;charset=utf-8"],"responses":{"200":{"description":"","schema":{"items":{"$ref":"#/definitions/User"},"type":"array"}}}},"post":{"consumes":["application/json;charset=utf-8"],"parameters":[{"in":"body","name":"body","required":true,"schema":{"$ref":"#/definitions/User"}}],"produces":["application/json;charset=utf-8"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/UserId"}},"400":{"description":"Invalid `body`"}}}},"/{user_id}":{"get":{"parameters":[{"in":"path","name":"user_id","required":true,"type":"integer"}],"produces":["application/json;charset=utf-8"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/User"}},"400":{"description":"Invalid `user_id`"}}}}},"swagger":"2.0"} +-- {"definitions":{"User":{"properties":{"age":{"maximum":9223372036854775807,"minimum":-9223372036854775808,"type":"integer"},"name":{"type":"string"}},"required":["name","age"],"type":"object"},"UserId":{"type":"integer"}},"info":{"title":"","version":""},"paths":{"/":{"get":{"produces":["application/json"],"responses":{"200":{"description":"","schema":{"items":{"$ref":"#/definitions/User"},"type":"array"}}}},"post":{"consumes":["application/json"],"parameters":[{"in":"body","name":"body","required":true,"schema":{"$ref":"#/definitions/User"}}],"produces":["application/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/UserId"}},"400":{"description":"Invalid `body`"}}}},"/{user_id}":{"get":{"parameters":[{"in":"path","name":"user_id","required":true,"type":"integer"}],"produces":["application/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/User"}},"400":{"description":"Invalid `user_id`"}}}}},"swagger":"2.0"} -- -- By default @'toSwagger'@ will generate specification for all API routes, parameters, headers, responses and data schemas. -- @@ -125,7 +125,7 @@ import Servant.Swagger.Test -- & info.license ?~ "MIT" -- & host ?~ "example.com" -- :} --- {"definitions":{"User":{"properties":{"age":{"maximum":9223372036854775807,"minimum":-9223372036854775808,"type":"integer"},"name":{"type":"string"}},"required":["name","age"],"type":"object"},"UserId":{"type":"integer"}},"host":"example.com","info":{"description":"This is an API for the Users service","license":{"name":"MIT"},"title":"User API","version":"1.0"},"paths":{"/":{"get":{"produces":["application/json;charset=utf-8"],"responses":{"200":{"description":"","schema":{"items":{"$ref":"#/definitions/User"},"type":"array"}}}},"post":{"consumes":["application/json;charset=utf-8"],"parameters":[{"in":"body","name":"body","required":true,"schema":{"$ref":"#/definitions/User"}}],"produces":["application/json;charset=utf-8"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/UserId"}},"400":{"description":"Invalid `body`"}}}},"/{user_id}":{"get":{"parameters":[{"in":"path","name":"user_id","required":true,"type":"integer"}],"produces":["application/json;charset=utf-8"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/User"}},"400":{"description":"Invalid `user_id`"}}}}},"swagger":"2.0"} +-- {"definitions":{"User":{"properties":{"age":{"maximum":9223372036854775807,"minimum":-9223372036854775808,"type":"integer"},"name":{"type":"string"}},"required":["name","age"],"type":"object"},"UserId":{"type":"integer"}},"host":"example.com","info":{"description":"This is an API for the Users service","license":{"name":"MIT"},"title":"User API","version":"1.0"},"paths":{"/":{"get":{"produces":["application/json"],"responses":{"200":{"description":"","schema":{"items":{"$ref":"#/definitions/User"},"type":"array"}}}},"post":{"consumes":["application/json"],"parameters":[{"in":"body","name":"body","required":true,"schema":{"$ref":"#/definitions/User"}}],"produces":["application/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/UserId"}},"400":{"description":"Invalid `body`"}}}},"/{user_id}":{"get":{"parameters":[{"in":"path","name":"user_id","required":true,"type":"integer"}],"produces":["application/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/User"}},"400":{"description":"Invalid `user_id`"}}}}},"swagger":"2.0"} -- -- It is also useful to annotate or modify certain endpoints. -- @'subOperations'@ provides a convenient way to zoom into a part of an API. @@ -143,7 +143,7 @@ import Servant.Swagger.Test -- & applyTagsFor getOps ["get" & description ?~ "GET operations"] -- & applyTagsFor postOps ["post" & description ?~ "POST operations"] -- :} --- {"definitions":{"User":{"properties":{"age":{"maximum":9223372036854775807,"minimum":-9223372036854775808,"type":"integer"},"name":{"type":"string"}},"required":["name","age"],"type":"object"},"UserId":{"type":"integer"}},"info":{"title":"","version":""},"paths":{"/":{"get":{"produces":["application/json;charset=utf-8"],"responses":{"200":{"description":"","schema":{"items":{"$ref":"#/definitions/User"},"type":"array"}}},"tags":["get"]},"post":{"consumes":["application/json;charset=utf-8"],"parameters":[{"in":"body","name":"body","required":true,"schema":{"$ref":"#/definitions/User"}}],"produces":["application/json;charset=utf-8"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/UserId"}},"400":{"description":"Invalid `body`"}},"tags":["post"]}},"/{user_id}":{"get":{"parameters":[{"in":"path","name":"user_id","required":true,"type":"integer"}],"produces":["application/json;charset=utf-8"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/User"}},"400":{"description":"Invalid `user_id`"}},"tags":["get"]}}},"swagger":"2.0","tags":[{"description":"GET operations","name":"get"},{"description":"POST operations","name":"post"}]} +-- {"definitions":{"User":{"properties":{"age":{"maximum":9223372036854775807,"minimum":-9223372036854775808,"type":"integer"},"name":{"type":"string"}},"required":["name","age"],"type":"object"},"UserId":{"type":"integer"}},"info":{"title":"","version":""},"paths":{"/":{"get":{"produces":["application/json"],"responses":{"200":{"description":"","schema":{"items":{"$ref":"#/definitions/User"},"type":"array"}}},"tags":["get"]},"post":{"consumes":["application/json"],"parameters":[{"in":"body","name":"body","required":true,"schema":{"$ref":"#/definitions/User"}}],"produces":["application/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/UserId"}},"400":{"description":"Invalid `body`"}},"tags":["post"]}},"/{user_id}":{"get":{"parameters":[{"in":"path","name":"user_id","required":true,"type":"integer"}],"produces":["application/json"],"responses":{"200":{"description":"","schema":{"$ref":"#/definitions/User"}},"400":{"description":"Invalid `user_id`"}},"tags":["get"]}}},"swagger":"2.0","tags":[{"description":"GET operations","name":"get"},{"description":"POST operations","name":"post"}]} -- -- This applies @\"get\"@ tag to the @GET@ endpoints and @\"post\"@ tag to the @POST@ endpoint of the User API. diff --git a/servant-swagger/test/Servant/SwaggerSpec.hs b/servant-swagger/test/Servant/SwaggerSpec.hs index a2d5a2836..ccb1609c7 100644 --- a/servant-swagger/test/Servant/SwaggerSpec.hs +++ b/servant-swagger/test/Servant/SwaggerSpec.hs @@ -117,7 +117,7 @@ todoAPI = }, "400": { "description": "Invalid `id`" } }, - "produces": [ "application/json;charset=utf-8" ], + "produces": [ "application/json" ], "parameters": [ { @@ -285,7 +285,7 @@ hackageAPI = } }, "produces":[ - "application/json;charset=utf-8" + "application/json" ], "tags":[ "users" @@ -306,7 +306,7 @@ hackageAPI = } }, "produces":[ - "application/json;charset=utf-8" + "application/json" ], "tags":[ "packages" @@ -327,7 +327,7 @@ hackageAPI = } }, "produces":[ - "application/json;charset=utf-8" + "application/json" ], "parameters":[ { @@ -401,7 +401,7 @@ getPostAPI = "description":"" } }, - "produces":[ "application/json;charset=utf-8" ] + "produces":[ "application/json" ] }, "get":{ "responses":{ @@ -412,7 +412,7 @@ getPostAPI = "description":"" } }, - "produces":[ "application/json;charset=utf-8" ], + "produces":[ "application/json" ], "tags":[ "get" ] } } @@ -498,7 +498,7 @@ uverbAPI = } }, "produces": [ - "application/json;charset=utf-8" + "application/json" ] } } diff --git a/servant/CHANGELOG.md b/servant/CHANGELOG.md index bfafa7a45..1c0fbaed3 100644 --- a/servant/CHANGELOG.md +++ b/servant/CHANGELOG.md @@ -991,7 +991,7 @@ Compatibility with GHC 9.4, see [PR #1592](https://github.com/haskell-servant/se ([#345](https://github.com/haskell-servant/servant/pull/345) , [#305](https://github.com/haskell-servant/servant/issues/305)) -* Default JSON content type change to `application/json;charset=utf-8`. +* Default JSON content type change to `application/json`. ([#263](https://github.com/haskell-servant/servant/issues/263)) Related browser bugs: [Chromium](https://bugs.chromium.org/p/chromium/issues/detail?id=438464) and diff --git a/servant/src/Servant/API/ContentTypes.hs b/servant/src/Servant/API/ContentTypes.hs index 1bb955162..f64a4327c 100644 --- a/servant/src/Servant/API/ContentTypes.hs +++ b/servant/src/Servant/API/ContentTypes.hs @@ -127,9 +127,8 @@ class Accept ctype where -- | @application/json@ instance Accept JSON where - contentTypes _ = - "application" M.// "json" M./: ("charset", "utf-8") - NE.:| ["application" M.// "json"] + contentType _ = + "application" M.// "json" -- | @application/x-www-form-urlencoded@ instance Accept FormUrlEncoded where diff --git a/servant/test/Servant/API/ContentTypesSpec.hs b/servant/test/Servant/API/ContentTypesSpec.hs index 8d4e2f77d..df2969b33 100644 --- a/servant/test/Servant/API/ContentTypesSpec.hs +++ b/servant/test/Servant/API/ContentTypesSpec.hs @@ -137,9 +137,9 @@ spec = describe "Servant.API.ContentTypes" $ do it "returns the Content-Type as the first element of the tuple" $ do handleAcceptH (Proxy :: Proxy '[JSON]) "*/*" (3 :: Int) - `shouldSatisfy` ((== "application/json;charset=utf-8") . fst . fromJust) + `shouldSatisfy` ((== "application/json") . fst . fromJust) handleAcceptH (Proxy :: Proxy '[PlainText, JSON]) "application/json" (3 :: Int) - `shouldSatisfy` ((== "application/json;charset=utf-8") . fst . fromJust) + `shouldSatisfy` ((== "application/json") . fst . fromJust) handleAcceptH (Proxy :: Proxy '[PlainText, JSON, OctetStream]) "application/octet-stream" @@ -149,13 +149,13 @@ spec = describe "Servant.API.ContentTypes" $ do it "returns the appropriately serialized representation" $ do property $ \x -> handleAcceptH (Proxy :: Proxy '[JSON]) "*/*" (x :: SomeData) - == Just ("application/json;charset=utf-8", encode x) + == Just ("application/json", encode x) it "respects the Accept spec ordering" $ do let highest a b c = selectMedia [ ("application/octet-stream", a) - , ("application/json;charset=utf-8", b) + , ("application/json", b) , ("text/plain;charset=utf-8", c) ]