You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generate API docs for your *servant* webservice. Feel free to also take a look at [servant-pandoc](https://github.com/mpickering/servant-pandoc) which uses this package to target a broad range of output formats using the excellent **pandoc**.
5
+
Generate API docs for your _servant_ webservice. Feel free to also take a look at [servant-pandoc](https://github.com/mpickering/servant-pandoc) which uses this package to target a broad range of output formats using the excellent **pandoc**.
6
6
7
7
## Example
8
8
9
9
See [here](https://github.com/haskell-servant/servant/blob/master/servant-docs/example/greet.md) for the output of the following program.
10
10
11
-
```haskell
11
+
```haskell
12
12
{-# LANGUAGE DataKinds #-}
13
-
{-# LANGUAGE PolyKinds #-}
14
-
{-# LANGUAGE TypeFamilies #-}
15
13
{-# LANGUAGE DeriveGeneric #-}
16
-
{-# LANGUAGE TypeOperators #-}
17
14
{-# LANGUAGE FlexibleInstances #-}
15
+
{-# LANGUAGE MultiParamTypeClasses #-}
18
16
{-# LANGUAGE OverloadedStrings #-}
17
+
{-# LANGUAGE PolyKinds #-}
18
+
{-# LANGUAGE TypeFamilies #-}
19
+
{-# LANGUAGE TypeOperators #-}
19
20
20
-
importData.Proxy
21
-
importData.Text
21
+
importData.Aeson (FromJSON, ToJSON)
22
+
importData.Proxy (Proxy (..))
23
+
importData.String.Conversions (cs)
24
+
importData.Text (Text)
25
+
importGHC.Generics (Generic)
26
+
importServant.API
27
+
( (:<|>),
28
+
(:>),
29
+
Capture,
30
+
Delete,
31
+
Get,
32
+
JSON,
33
+
MimeRender,
34
+
PlainText,
35
+
Post,
36
+
QueryParam,
37
+
ReqBody,
38
+
mimeRender,
39
+
)
22
40
importServant.Docs
41
+
( API,
42
+
DocCapture (..),
43
+
DocQueryParam (..),
44
+
ParamKind (..),
45
+
ToCapture,
46
+
ToParam,
47
+
ToSample,
48
+
docs,
49
+
markdown,
50
+
singleSample,
51
+
toCapture,
52
+
toParam,
53
+
toSamples,
54
+
)
23
55
24
56
-- our type for a Greeting message
25
57
dataGreet=Greet{_msg::Text}
@@ -29,22 +61,23 @@ data Greet = Greet { _msg :: Text }
29
61
-- 'MimeRender' instance for 'JSON'.
30
62
instanceFromJSONGreet
31
63
instanceToJSONGreet
64
+
instanceToSample()
32
65
33
66
-- We can also implement 'MimeRender' explicitly for additional formats.
34
67
instanceMimeRenderPlainTextGreetwhere
35
68
mimeRender Proxy (Greet s) ="<h1>"<> cs s <>"</h1>"
36
69
37
70
-- we provide a sample value for the 'Greet' type
38
71
instanceToSampleGreetwhere
39
-
toSample =Just g
40
-
72
+
toSamples _ = singleSample g
41
73
where g =Greet"Hello, haskeller!"
42
74
43
75
instanceToParam (QueryParam"capital"Bool) where
44
76
toParam _ =
45
77
DocQueryParam"capital"
46
78
["true", "false"]
47
79
"Get the greeting message in uppercase (true) or not (false). Default is false."
80
+
Normal
48
81
49
82
instanceToCapture (Capture"name"Text) where
50
83
toCapture _ =DocCapture"name""name of the person to greet"
@@ -55,8 +88,8 @@ instance ToCapture (Capture "greetid" Text) where
0 commit comments