on master help sign in
Switch to encodePretty in sampleByteString.
3898c19Julian K. Arni
example/greet.hs+2−1
@@ -3,6 +3,7 @@
3{-# LANGUAGE TypeOperators #-}
3{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE OverloadedStrings #-}
6+{-# OPTIONS_GHC -fno-warn-orphans #-}
6import Data.Aeson
7import Data.Aeson
7import Data.Proxy
8import Data.Proxy
8import Data.Text
9import Data.Text
@@ -60,4 +61,4 @@ docsGreet :: API
60docsGreet = docs testApi
61docsGreet = docs testApi
61
62
62main :: IO ()
63main :: IO ()
63−main = putStrLn $ markdown docsGreet
64+main = putStrLn $ markdown docsGreet
example/greet.md+19−10
@@ -1,52 +1,61 @@
1+
1POST /greet
2POST /greet
2-----------
3-----------
3
4
4−**Request Body**:
5+**Request Body**:
5
6
6``` javascript
7``` javascript
8+{
7−{"msg":"Hello, haskeller!"}
9+ "msg": "Hello, haskeller!"
10+}
8```
11```
9
12
10−**Response**:
13+**Response**:
11
14
12 - Status code 201
15 - Status code 201
13 - Response body as below.
16 - Response body as below.
14
17
15``` javascript
18``` javascript
19+{
16−{"msg":"Hello, haskeller!"}
20+ "msg": "Hello, haskeller!"
21+}
17```
22```
18
23
19GET /hello/:name
24GET /hello/:name
20----------------
25----------------
21
26
22−**Captures**:
27+**Captures**:
23
28
24- *name*: name of the person to greet
29- *name*: name of the person to greet
25
30
26−**GET Parameters**:
31+**GET Parameters**:
27
32
28 - capital
33 - capital
29 - **Values**: *true, false*
34 - **Values**: *true, false*
30 - **Description**: Get the greeting message in uppercase (true) or not (false). Default is false.
35 - **Description**: Get the greeting message in uppercase (true) or not (false). Default is false.
31
36
32
37
33−**Response**:
38+**Response**:
34
39
35 - Status code 200
40 - Status code 200
36 - Response body as below.
41 - Response body as below.
37
42
38``` javascript
43``` javascript
44+{
39−{"msg":"Hello, haskeller!"}
45+ "msg": "Hello, haskeller!"
46+}
40```
47```
41
48
42DELETE /greet/:greetid
49DELETE /greet/:greetid
43----------------------
50----------------------
44
51
45−**Captures**:
52+**Captures**:
46
53
47- *greetid*: identifier of the greet msg to remove
54- *greetid*: identifier of the greet msg to remove
48
55
49−**Response**:
56+**Response**:
50
57
51 - Status code 204
58 - Status code 204
52 - No response body
59 - No response body
60+
61+
servant-docs.cabal+1
@@ -26,6 +26,7 @@ library
26 build-depends:
26 build-depends:
27 base >=4.7 && <5
27 base >=4.7 && <5
28 , aeson
28 , aeson
29+ , aeson-pretty < 0.8
29 , bytestring
30 , bytestring
30 , hashable
31 , hashable
31 , lens
32 , lens
src/Servant/Docs.hs+3−2
@@ -109,6 +109,7 @@ module Servant.Docs
109
109
110import Control.Lens hiding (Action)
110import Control.Lens hiding (Action)
111import Data.Aeson
111import Data.Aeson
112+import Data.Aeson.Encode.Pretty (encodePretty)
112import Data.ByteString.Lazy.Char8 (ByteString)
113import Data.ByteString.Lazy.Char8 (ByteString)
113import Data.Hashable
114import Data.Hashable
114import Data.HashMap.Strict (HashMap)
115import Data.HashMap.Strict (HashMap)
@@ -333,7 +334,7 @@ instance ToSample () where
333 toSample = Just ()
334 toSample = Just ()
334
335
335sampleByteString :: forall a . ToSample a => Proxy a -> Maybe ByteString
336sampleByteString :: forall a . ToSample a => Proxy a -> Maybe ByteString
336−sampleByteString Proxy = fmap encode (toSample :: Maybe a)
337+sampleByteString Proxy = fmap encodePretty (toSample :: Maybe a)
337
338
338-- | The class that helps us automatically get documentation
339-- | The class that helps us automatically get documentation
339-- for GET parameters.
340-- for GET parameters.
@@ -605,4 +606,4 @@ toHtml md =
605 "</pre>" ++
606 "</pre>" ++
606 "</body>" ++
607 "</body>" ++
607 "</html>"
608 "</html>"
608−-}
609+-}