@@ -1,7 +1,64 @@
11name: servant-docs
22version: 0.2
3−-- synopsis:
4−-- description:
3+synopsis: generate API docs for your servant webservice
4+description:
5+ Library for generating API docs from a servant API definition.
6+ .
7+ Runnable example below that prints API docs in markdown.
8+ .
9+ > {-# LANGUAGE DataKinds #-}
10+ > {-# LANGUAGE PolyKinds #-}
11+ > {-# LANGUAGE TypeFamilies #-}
12+ > {-# LANGUAGE DeriveGeneric #-}
13+ > {-# LANGUAGE TypeOperators #-}
14+ > {-# LANGUAGE FlexibleInstances #-}
15+ > {-# LANGUAGE OverloadedStrings #-}
16+ >
17+ > import Data.Proxy
18+ > import Data.Text
19+ > import Servant
20+ >
21+ > -- our type for a Greeting message
22+ > data Greet = Greet { _msg :: Text }
23+ > deriving (Generic, Show)
24+ >
25+ > -- we get our JSON serialization for free
26+ > instance FromJSON Greet
27+ > instance ToJSON Greet
28+ >
29+ > -- we provide a sample value for the 'Greet' type
30+ > instance ToSample Greet where
31+ > toSample = Just g
32+ >
33+ > where g = Greet "Hello, haskeller!"
34+ >
35+ > instance ToParam (QueryParam "capital" Bool) where
36+ > toParam _ =
37+ > DocQueryParam "capital"
38+ > ["true", "false"]
39+ > "Get the greeting message in uppercase (true) or not (false). Default is false."
40+ >
41+ > instance ToCapture (Capture "name" Text) where
42+ > toCapture _ = DocCapture "name" "name of the person to greet"
43+ >
44+ > instance ToCapture (Capture "greetid" Text) where
45+ > toCapture _ = DocCapture "greetid" "identifier of the greet msg to remove"
46+ >
47+ > -- API specification
48+ > type TestApi =
49+ > "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get Greet
50+ > :<|> "greet" :> RQBody Greet :> Post Greet
51+ > :<|> "delete" :> Capture "greetid" Text :> Delete
52+ >
53+ > testApi :: Proxy TestApi
54+ > testApi = Proxy
55+ >
56+ > -- Generate the Documentation's ADT
57+ > greetDocs :: API
58+ > greetDocs = docs testApi
59+ >
60+ > main :: IO ()
61+ > main = putStrLn $ markdown greetDocs
562license: BSD3
663license-file: LICENSE
764author: Alp Mestanogullari, Sönke Hahn, Julian K. Arni
@@ -11,6 +68,11 @@ category: Web
1168build-type: Simple
1269cabal-version: >=1.10
1370tested-with: GHC >= 7.8
71+homepage: http://haskell-servant.github.io/
72+Bug-reports: http://github.com/haskell-servant/servant-docs/issues
73+source-repository head
74+ type: git
75+ location: http://github.com/haskell-servant/servant-docs.git
1476
1577library
1678 exposed-modules:
@@ -27,11 +89,11 @@ library
2789 , unordered-containers
2890 hs-source-dirs: src
2991 default-language: Haskell2010
30− ghc-options: -O0 -Wall
92+ ghc-options: -Wall
3193
3294executable greet-docs
3395 main-is: greet.hs
3496 hs-source-dirs: example
35− ghc-options: -O0 -Wall
97+ ghc-options: -Wall
3698 build-depends: base, aeson, servant, servant-docs, text
3799 default-language: Haskell2010