@@ -0,0 +1,94 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE TypeFamilies #-}
3+{-# LANGUAGE TypeOperators #-}
4+{-# LANGUAGE FlexibleInstances #-}
5+{-# LANGUAGE OverloadedStrings #-}
6+{-# LANGUAGE MultiParamTypeClasses #-}
9+import Data.ByteString.Lazy (ByteString)
10+import Data.Text.Lazy (pack)
11+import Data.Text.Lazy.Encoding (encodeUtf8)
12+import Network.HTTP.Types
16+import Servant.Docs.Pandoc (pandoc)
17+import Text.Pandoc.Options (def, WriterOptions(..))
18+import Text.Pandoc.Writers.HTML (writeHtmlString)
21+type DocsAPI = GS3.API :<|> Raw
23+instance ToCapture (Capture "x" Int) where
24+ toCapture _ = DocCapture "x" "(integer) position on the x axis"
26+instance ToCapture (Capture "y" Int) where
27+ toCapture _ = DocCapture "y" "(integer) position on the y axis"
29+instance ToSample GS3.Position GS3.Position where
30+ toSample _ = Just (GS3.Position 3 14)
32+instance ToParam (QueryParam "name" String) where
35+ ["Alp", "John Doe", "..."]
36+ "Name of the person to say hello to."
39+instance ToSample GS3.HelloMessage GS3.HelloMessage where
41+ [ ("When a value is provided for 'name'", GS3.HelloMessage "Hello, Alp")
42+ , ("When 'name' is not specified", GS3.HelloMessage "Hello, anonymous coward")
46+ci = GS3.ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"]
48+instance ToSample GS3.ClientInfo GS3.ClientInfo where
51+instance ToSample GS3.Email GS3.Email where
52+ toSample _ = Just (GS3.emailForClient ci)
60+ . writeHtmlString opts
62+ $ docsWithIntros [intro] GS3.api
64+ where opts = def { writerHtml5 = True
65+ , writerTableOfContents = True
66+ , writerHighlight = True
67+ , writerStandalone = True
70+ [ "<!DOCTYPE html><html>"
72+ , "<meta charset=\"UTF-8\">"
73+ , "<title>API Docs - $title$</title>"
83+ intro = DocIntro "Welcome" ["This is our super webservice's API.", "Enjoy!"]
85+server :: Server DocsAPI
86+server = GS3.server :<|> serveDocs
88+ where serveDocs _ respond =
89+ respond $ responseLBS ok200 [html] docsBS
91+ html = ("Content-Type", "text/html")
94+app = serve api server