@@ -115,6 +115,7 @@ import Data.HashMap.Strict (HashMap)
115115import Data.List
116116import Data.Monoid
117117import Data.Proxy
118+import Data.Text (Text, pack, unpack)
118119import Data.String.Conversions
119120import GHC.Generics
120121import GHC.TypeLits
@@ -255,6 +256,7 @@ defResponse = Response 200 Nothing
255256-- to transform an action and add some information to it.
256257data Action = Action
257258 { _captures :: [DocCapture] -- type collected + user supplied info
259+ , _headers :: [Text] -- type collected
258260 , _params :: [DocQueryParam] -- type collected + user supplied info
259261 , _rqbody :: Maybe ByteString -- user supplied
260262 , _response :: Response -- user supplied
@@ -272,6 +274,7 @@ data Action = Action
272274defAction :: Action
273275defAction =
274276 Action []
277+ []
275278 []
276279 Nothing
277280 defResponse
@@ -366,6 +369,7 @@ markdown = unlines . concat . map (uncurry printEndpoint) . HM.toList
366369 replicate len '-' :
367370 "" :
368371 capturesStr (action ^. captures) ++
372+ headersStr (action ^. headers) ++
369373 paramsStr (action ^. params) ++
370374 rqbodyStr (action ^. rqbody) ++
371375 responseStr (action ^. response) ++
@@ -385,6 +389,13 @@ markdown = unlines . concat . map (uncurry printEndpoint) . HM.toList
385389 captureStr cap =
386390 "- *" ++ (cap ^. capSymbol) ++ "*: " ++ (cap ^. capDesc)
387391
392+ headersStr :: [Text] -> [String]
393+ headersStr [] = []
394+ headersStr l = [""] ++ map headerStr l ++ [""]
395+
396+ where headerStr hname = "- This endpoint is sensitive to the value of the **"
397+ ++ unpack hname ++ "** HTTP header."
398+
388399 paramsStr :: [DocQueryParam] -> [String]
389400 paramsStr [] = []
390401 paramsStr l =
@@ -481,6 +492,15 @@ instance ToSample a => HasDocs (Get a) where
481492 action' = action & response.respBody .~ sampleByteString p
482493 p = Proxy :: Proxy a
483494
495+instance (KnownSymbol sym, HasDocs sublayout)
496+ => HasDocs (Header sym a :> sublayout) where
497+ docsFor Proxy (endpoint, action) =
498+ docsFor sublayoutP (endpoint, action')
499+
500+ where sublayoutP = Proxy :: Proxy sublayout
501+ action' = over headers (|> headername) action
502+ headername = pack $ symbolVal (Proxy :: Proxy sym)
503+
484504instance ToSample a => HasDocs (Post a) where
485505 docsFor Proxy (endpoint, action) =
486506 single endpoint' action'