From 73e11a5e6c1d67dd642da4cfc4f9547663bcc01d Mon Sep 17 00:00:00 2001 From: Tim Emiola Date: Sat, 25 Aug 2018 10:02:14 +0900 Subject: [PATCH] Change HasDocs instances for Summary and Description - if a description follows a summary, the summary is used as a title and the lines of description form a body. - if a description occurs without a preceding summary, it's first line is used as a title, and the remainder are used as a body. --- servant-docs/src/Servant/Docs/Internal.hs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/servant-docs/src/Servant/Docs/Internal.hs b/servant-docs/src/Servant/Docs/Internal.hs index 9bf5bf12..bcef6c8f 100644 --- a/servant-docs/src/Servant/Docs/Internal.hs +++ b/servant-docs/src/Servant/Docs/Internal.hs @@ -930,6 +930,17 @@ instance HasDocs Raw where docsFor _proxy (endpoint, action) _ = single endpoint action +instance (KnownSymbol summ, KnownSymbol desc, HasDocs api) + => HasDocs (Summary summ :> Description desc :> api) where + + docsFor Proxy (endpoint, action) = + docsFor subApiP (endpoint, action') + + where subApiP = Proxy :: Proxy api + action' = over notes (|> note) action + note = DocNote title body + title = symbolVal (Proxy :: Proxy summ) + body = lines $ symbolVal (Proxy :: Proxy desc) instance (KnownSymbol desc, HasDocs api) => HasDocs (Description desc :> api) where @@ -939,17 +950,20 @@ instance (KnownSymbol desc, HasDocs api) where subApiP = Proxy :: Proxy api action' = over notes (|> note) action - note = DocNote (symbolVal (Proxy :: Proxy desc)) [] + description = symbolVal (Proxy :: Proxy desc) + note = mkNote $ lines $ description + mkNote (x:xs) = DocNote x xs + mkNote [] = DocNote description [] -instance (KnownSymbol desc, HasDocs api) - => HasDocs (Summary desc :> api) where +instance (KnownSymbol summ, HasDocs api) + => HasDocs (Summary summ :> api) where docsFor Proxy (endpoint, action) = docsFor subApiP (endpoint, action') where subApiP = Proxy :: Proxy api action' = over notes (|> note) action - note = DocNote (symbolVal (Proxy :: Proxy desc)) [] + note = DocNote (symbolVal (Proxy :: Proxy summ)) [] -- TODO: We use 'AllMimeRender' here because we need to be able to show the -- example data. However, there's no reason to believe that the instances of