From 89e0a98ac501fe0c86b2750b1038ef04ea905c37 Mon Sep 17 00:00:00 2001 From: Ivan Lazar Miljenovic Date: Fri, 28 Jul 2017 16:31:55 +1000 Subject: [PATCH 1/2] Document the type of endpoint a parameter belongs to Closes #760 --- servant-docs/src/Servant/Docs/Internal.hs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/servant-docs/src/Servant/Docs/Internal.hs b/servant-docs/src/Servant/Docs/Internal.hs index f253715e..fc2d4e5c 100644 --- a/servant-docs/src/Servant/Docs/Internal.hs +++ b/servant-docs/src/Servant/Docs/Internal.hs @@ -529,14 +529,16 @@ markdown api = unlines $ authStr (action ^. authInfo) ++ capturesStr (action ^. captures) ++ headersStr (action ^. headers) ++ - paramsStr (action ^. params) ++ + paramsStr meth (action ^. params) ++ rqbodyStr (action ^. rqtypes) (action ^. rqbody) ++ responseStr (action ^. response) ++ [] - where str = "## " ++ BSC.unpack (endpoint^.method) + where str = "## " ++ BSC.unpack meth ++ " " ++ showPath (endpoint^.path) + meth = endpoint ^. method + introsStr :: [DocIntro] -> [String] introsStr = concatMap introStr @@ -593,23 +595,23 @@ markdown api = unlines $ where headerStr hname = "- This endpoint is sensitive to the value of the **" ++ unpack hname ++ "** HTTP header." - paramsStr :: [DocQueryParam] -> [String] - paramsStr [] = [] - paramsStr l = - "#### GET Parameters:" : + paramsStr :: HTTP.Method -> [DocQueryParam] -> [String] + paramsStr _ [] = [] + paramsStr m l = + ("#### " ++ cs m ++ " Parameters:") : "" : - map paramStr l ++ + map (paramStr m) l ++ "" : [] - paramStr param = unlines $ + paramStr m param = unlines $ ("- " ++ param ^. paramName) : (if (not (null values) || param ^. paramKind /= Flag) then [" - **Values**: *" ++ intercalate ", " values ++ "*"] else []) ++ (" - **Description**: " ++ param ^. paramDesc) : (if (param ^. paramKind == List) - then [" - This parameter is a **list**. All GET parameters with the name " + then [" - This parameter is a **list**. All " ++ cs m ++ " parameters with the name " ++ param ^. paramName ++ "[] will forward their values in a list to the handler."] else []) ++ (if (param ^. paramKind == Flag) From 256ee412548cce1af827703dfc3b23c0a335446a Mon Sep 17 00:00:00 2001 From: Ivan Lazar Miljenovic Date: Fri, 28 Jul 2017 16:39:05 +1000 Subject: [PATCH 2/2] Update documentation such that it isn't just for GET --- servant-docs/src/Servant/Docs/Internal.hs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/servant-docs/src/Servant/Docs/Internal.hs b/servant-docs/src/Servant/Docs/Internal.hs index fc2d4e5c..43c24cef 100644 --- a/servant-docs/src/Servant/Docs/Internal.hs +++ b/servant-docs/src/Servant/Docs/Internal.hs @@ -125,9 +125,10 @@ data DocCapture = DocCapture , _capDesc :: String -- user supplied } deriving (Eq, Ord, Show) --- | A type to represent a /GET/ parameter from the Query String. Holds its name, --- the possible values (leave empty if there isn't a finite number of them), --- and a description of how it influences the output or behavior. +-- | A type to represent a /GET/ (or other possible 'HTTP.Method') +-- parameter from the Query String. Holds its name, the possible +-- values (leave empty if there isn't a finite number of them), and +-- a description of how it influences the output or behavior. -- -- Write a 'ToParam' instance for your GET parameter types data DocQueryParam = DocQueryParam @@ -185,7 +186,7 @@ defaultDocOptions :: DocOptions defaultDocOptions = DocOptions { _maxSamples = 5 } --- | Type of GET parameter: +-- | Type of GET (or other 'HTTP.Method') parameter: -- -- - Normal corresponds to @QueryParam@, i.e your usual GET parameter -- - List corresponds to @QueryParams@, i.e GET parameters with multiple values @@ -235,7 +236,7 @@ defResponse = Response -- at an endpoint, with its lenses: -- -- - List of captures ('captures') --- - List of GET parameters ('params') +-- - List of GET (or other 'HTTP.Method') parameters ('params') -- - What the request body should look like, if any is requested ('rqbody') -- - What the response should be if everything goes well ('response') -- @@ -263,7 +264,7 @@ combineAction :: Action -> Action -> Action Action a c h p n m ts body resp `combineAction` Action a' c' h' p' n' m' _ _ _ = Action (a <> a') (c <> c') (h <> h') (p <> p') (n <> n') (m <> m') ts body resp --- Default 'Action'. Has no 'captures', no GET 'params', expects +-- Default 'Action'. Has no 'captures', no query 'params', expects -- no request body ('rqbody') and the typical response is 'defResponse'. -- -- Tweakable with lenses. @@ -487,8 +488,8 @@ sampleByteStrings ctypes@Proxy Proxy = enc (t, s) = uncurry (t,,) <$> allMimeRender ctypes s in concatMap enc samples' --- | The class that helps us automatically get documentation --- for GET parameters. +-- | The class that helps us automatically get documentation for GET +-- (or other 'HTTP.Method') parameters. -- -- Example of an instance: --