Merge pull request #1 from haskell-servant/jkarni/encodePretty
Switch to encodePretty in sampleByteString.
This commit is contained in:
commit
87b7c8e376
4 changed files with 25 additions and 13 deletions
|
@ -3,6 +3,7 @@
|
||||||
{-# LANGUAGE TypeOperators #-}
|
{-# LANGUAGE TypeOperators #-}
|
||||||
{-# LANGUAGE FlexibleInstances #-}
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.Proxy
|
import Data.Proxy
|
||||||
import Data.Text
|
import Data.Text
|
||||||
|
@ -60,4 +61,4 @@ docsGreet :: API
|
||||||
docsGreet = docs testApi
|
docsGreet = docs testApi
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = putStrLn $ markdown docsGreet
|
main = putStrLn $ markdown docsGreet
|
||||||
|
|
|
@ -1,52 +1,61 @@
|
||||||
|
|
||||||
POST /greet
|
POST /greet
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
**Request Body**:
|
**Request Body**:
|
||||||
|
|
||||||
``` javascript
|
``` javascript
|
||||||
{"msg":"Hello, haskeller!"}
|
{
|
||||||
|
"msg": "Hello, haskeller!"
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Response**:
|
**Response**:
|
||||||
|
|
||||||
- Status code 201
|
- Status code 201
|
||||||
- Response body as below.
|
- Response body as below.
|
||||||
|
|
||||||
``` javascript
|
``` javascript
|
||||||
{"msg":"Hello, haskeller!"}
|
{
|
||||||
|
"msg": "Hello, haskeller!"
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
GET /hello/:name
|
GET /hello/:name
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
**Captures**:
|
**Captures**:
|
||||||
|
|
||||||
- *name*: name of the person to greet
|
- *name*: name of the person to greet
|
||||||
|
|
||||||
**GET Parameters**:
|
**GET Parameters**:
|
||||||
|
|
||||||
- capital
|
- capital
|
||||||
- **Values**: *true, false*
|
- **Values**: *true, false*
|
||||||
- **Description**: Get the greeting message in uppercase (true) or not (false). Default is false.
|
- **Description**: Get the greeting message in uppercase (true) or not (false). Default is false.
|
||||||
|
|
||||||
|
|
||||||
**Response**:
|
**Response**:
|
||||||
|
|
||||||
- Status code 200
|
- Status code 200
|
||||||
- Response body as below.
|
- Response body as below.
|
||||||
|
|
||||||
``` javascript
|
``` javascript
|
||||||
{"msg":"Hello, haskeller!"}
|
{
|
||||||
|
"msg": "Hello, haskeller!"
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
DELETE /greet/:greetid
|
DELETE /greet/:greetid
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
**Captures**:
|
**Captures**:
|
||||||
|
|
||||||
- *greetid*: identifier of the greet msg to remove
|
- *greetid*: identifier of the greet msg to remove
|
||||||
|
|
||||||
**Response**:
|
**Response**:
|
||||||
|
|
||||||
- Status code 204
|
- Status code 204
|
||||||
- No response body
|
- No response body
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ library
|
||||||
build-depends:
|
build-depends:
|
||||||
base >=4.7 && <5
|
base >=4.7 && <5
|
||||||
, aeson
|
, aeson
|
||||||
|
, aeson-pretty < 0.8
|
||||||
, bytestring
|
, bytestring
|
||||||
, hashable
|
, hashable
|
||||||
, lens
|
, lens
|
||||||
|
|
|
@ -109,6 +109,7 @@ module Servant.Docs
|
||||||
|
|
||||||
import Control.Lens hiding (Action)
|
import Control.Lens hiding (Action)
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
|
import Data.Aeson.Encode.Pretty (encodePretty)
|
||||||
import Data.ByteString.Lazy.Char8 (ByteString)
|
import Data.ByteString.Lazy.Char8 (ByteString)
|
||||||
import Data.Hashable
|
import Data.Hashable
|
||||||
import Data.HashMap.Strict (HashMap)
|
import Data.HashMap.Strict (HashMap)
|
||||||
|
@ -333,7 +334,7 @@ instance ToSample () where
|
||||||
toSample = Just ()
|
toSample = Just ()
|
||||||
|
|
||||||
sampleByteString :: forall a . ToSample a => Proxy a -> Maybe ByteString
|
sampleByteString :: forall a . ToSample a => Proxy a -> Maybe ByteString
|
||||||
sampleByteString Proxy = fmap encode (toSample :: Maybe a)
|
sampleByteString Proxy = fmap encodePretty (toSample :: Maybe a)
|
||||||
|
|
||||||
-- | The class that helps us automatically get documentation
|
-- | The class that helps us automatically get documentation
|
||||||
-- for GET parameters.
|
-- for GET parameters.
|
||||||
|
@ -605,4 +606,4 @@ toHtml md =
|
||||||
"</pre>" ++
|
"</pre>" ++
|
||||||
"</body>" ++
|
"</body>" ++
|
||||||
"</html>"
|
"</html>"
|
||||||
-}
|
-}
|
||||||
|
|
Loading…
Add table
Reference in a new issue