on master help sign in
Merge pull request #1 from haskell-servant/jkarni/encodePretty

Switch to encodePretty in sampleByteString.

commit87b7c8e376a306a4d9de6d54434c5de70bad7d38 authorJulian Arni <jkarni@gmail.com> dateSat 20 Dec 2014, 22:09 (12 years ago) parent2d2c46e3898c19
4 files changed+25−13
example/greet.hs+2−1 example/greet.md+19−10 servant-docs.cabal+1 src/Servant/Docs.hs+3−2
example/greet.hs+2−1
@@ -3,6 +3,7 @@
33{-# LANGUAGE TypeOperators #-}
44{-# LANGUAGE FlexibleInstances #-}
55{-# LANGUAGE OverloadedStrings #-}
6+{-# OPTIONS_GHC -fno-warn-orphans #-}
67import Data.Aeson
78import Data.Proxy
89import Data.Text
@@ -60,4 +61,4 @@ docsGreet :: API
6061docsGreet = docs testApi
6162
6263main :: IO ()
63−main = putStrLn $ markdown docsGreet
64+main = putStrLn $ markdown docsGreet
example/greet.md+19−10
@@ -1,52 +1,61 @@
1+
12POST /greet
23-----------
34
4−**Request Body**:
5+**Request Body**:
56
67``` javascript
7−{"msg":"Hello, haskeller!"}
8+{
9+ "msg": "Hello, haskeller!"
10+}
811```
912
10−**Response**:
13+**Response**:
1114
1215 - Status code 201
1316 - Response body as below.
1417
1518``` javascript
16−{"msg":"Hello, haskeller!"}
19+{
20+ "msg": "Hello, haskeller!"
21+}
1722```
1823
1924GET /hello/:name
2025----------------
2126
22−**Captures**:
27+**Captures**:
2328
2429- *name*: name of the person to greet
2530
26−**GET Parameters**:
31+**GET Parameters**:
2732
2833 - capital
2934 - **Values**: *true, false*
3035 - **Description**: Get the greeting message in uppercase (true) or not (false). Default is false.
3136
3237
33−**Response**:
38+**Response**:
3439
3540 - Status code 200
3641 - Response body as below.
3742
3843``` javascript
39−{"msg":"Hello, haskeller!"}
44+{
45+ "msg": "Hello, haskeller!"
46+}
4047```
4148
4249DELETE /greet/:greetid
4350----------------------
4451
45−**Captures**:
52+**Captures**:
4653
4754- *greetid*: identifier of the greet msg to remove
4855
49−**Response**:
56+**Response**:
5057
5158 - Status code 204
5259 - No response body
60+
61+
servant-docs.cabal+1
@@ -26,6 +26,7 @@ library
2626 build-depends:
2727 base >=4.7 && <5
2828 , aeson
29+ , aeson-pretty < 0.8
2930 , bytestring
3031 , hashable
3132 , lens
src/Servant/Docs.hs+3−2
@@ -109,6 +109,7 @@ module Servant.Docs
109109
110110import Control.Lens hiding (Action)
111111import Data.Aeson
112+import Data.Aeson.Encode.Pretty (encodePretty)
112113import Data.ByteString.Lazy.Char8 (ByteString)
113114import Data.Hashable
114115import Data.HashMap.Strict (HashMap)
@@ -333,7 +334,7 @@ instance ToSample () where
333334 toSample = Just ()
334335
335336sampleByteString :: forall a . ToSample a => Proxy a -> Maybe ByteString
336−sampleByteString Proxy = fmap encode (toSample :: Maybe a)
337+sampleByteString Proxy = fmap encodePretty (toSample :: Maybe a)
337338
338339-- | The class that helps us automatically get documentation
339340-- for GET parameters.
@@ -605,4 +606,4 @@ toHtml md =
605606 "</pre>" ++
606607 "</body>" ++
607608 "</html>"
608−-}
609+-}