git.iko.soy/typeable/servant
on master help sign in
Merge pull request #790 from ivan-m/query-param-method

Document the type of endpoint a parameter belongs to

commit24035ddd853a8a4d5772a42c2698efe318b40ee1 authorOleg Grenrus <oleg.grenrus@iki.fi> dateMon 31 Jul 2017, 11:41 (9 years ago) parenta9bc22d6fc4c73
1 file changed+21−18
servant-docs/src/Servant/Docs/Internal.hs+21−18
servant-docs/src/Servant/Docs/Internal.hs+21−18
@@ -125,9 +125,10 @@ data DocCapture = DocCapture
125125 , _capDesc :: String -- user supplied
126126 } deriving (Eq, Ord, Show)
127127
128−-- | A type to represent a /GET/ parameter from the Query String. Holds its name,
129−-- the possible values (leave empty if there isn't a finite number of them),
130−-- and a description of how it influences the output or behavior.
128+-- | A type to represent a /GET/ (or other possible 'HTTP.Method')
129+-- parameter from the Query String. Holds its name, the possible
130+-- values (leave empty if there isn't a finite number of them), and
131+-- a description of how it influences the output or behavior.
131132--
132133-- Write a 'ToParam' instance for your GET parameter types
133134data DocQueryParam = DocQueryParam
@@ -185,7 +186,7 @@ defaultDocOptions :: DocOptions
185186defaultDocOptions = DocOptions
186187 { _maxSamples = 5 }
187188
188−-- | Type of GET parameter:
189+-- | Type of GET (or other 'HTTP.Method') parameter:
189190--
190191-- - Normal corresponds to @QueryParam@, i.e your usual GET parameter
191192-- - List corresponds to @QueryParams@, i.e GET parameters with multiple values
@@ -235,7 +236,7 @@ defResponse = Response
235236-- at an endpoint, with its lenses:
236237--
237238-- - List of captures ('captures')
238−-- - List of GET parameters ('params')
239+-- - List of GET (or other 'HTTP.Method') parameters ('params')
239240-- - What the request body should look like, if any is requested ('rqbody')
240241-- - What the response should be if everything goes well ('response')
241242--
@@ -263,8 +264,8 @@ combineAction :: Action -> Action -> Action
263264Action a c h p n m ts body resp `combineAction` Action a' c' h' p' n' m' _ _ _ =
264265 Action (a <> a') (c <> c') (h <> h') (p <> p') (n <> n') (m <> m') ts body resp
265266
266−-- | Default 'Action'. Has no 'captures', no GET 'params', expects no
267−-- request body ('rqbody') and the typical response is 'defResponse'.
267+-- | Default 'Action'. Has no 'captures', no query 'params', expects
268+-- no request body ('rqbody') and the typical response is 'defResponse'.
268269--
269270-- Tweakable with lenses.
270271--
@@ -487,8 +488,8 @@ sampleByteStrings ctypes@Proxy Proxy =
487488 enc (t, s) = uncurry (t,,) <$> allMimeRender ctypes s
488489 in concatMap enc samples'
489490
490−-- | The class that helps us automatically get documentation
491−-- for GET parameters.
491+-- | The class that helps us automatically get documentation for GET
492+-- (or other 'HTTP.Method') parameters.
492493--
493494-- Example of an instance:
494495--
@@ -529,14 +530,16 @@ markdown api = unlines $
529530 authStr (action ^. authInfo) ++
530531 capturesStr (action ^. captures) ++
531532 headersStr (action ^. headers) ++
532− paramsStr (action ^. params) ++
533+ paramsStr meth (action ^. params) ++
533534 rqbodyStr (action ^. rqtypes) (action ^. rqbody) ++
534535 responseStr (action ^. response) ++
535536 []
536537
537− where str = "## " ++ BSC.unpack (endpoint^.method)
538+ where str = "## " ++ BSC.unpack meth
538539 ++ " " ++ showPath (endpoint^.path)
539540
541+ meth = endpoint ^. method
542+
540543 introsStr :: [DocIntro] -> [String]
541544 introsStr = concatMap introStr
542545
@@ -598,23 +601,23 @@ markdown api = unlines $
598601 where headerStr hname = "- This endpoint is sensitive to the value of the **"
599602 ++ unpack hname ++ "** HTTP header."
600603
601− paramsStr :: [DocQueryParam] -> [String]
602− paramsStr [] = []
603− paramsStr l =
604− "#### GET Parameters:" :
604+ paramsStr :: HTTP.Method -> [DocQueryParam] -> [String]
605+ paramsStr _ [] = []
606+ paramsStr m l =
607+ ("#### " ++ cs m ++ " Parameters:") :
605608 "" :
606− map paramStr l ++
609+ map (paramStr m) l ++
607610 "" :
608611 []
609612
610− paramStr param = unlines $
613+ paramStr m param = unlines $
611614 ("- " ++ param ^. paramName) :
612615 (if (not (null values) || param ^. paramKind /= Flag)
613616 then [" - **Values**: *" ++ intercalate ", " values ++ "*"]
614617 else []) ++
615618 (" - **Description**: " ++ param ^. paramDesc) :
616619 (if (param ^. paramKind == List)
617− then [" - This parameter is a **list**. All GET parameters with the name "
620+ then [" - This parameter is a **list**. All " ++ cs m ++ " parameters with the name "
618621 ++ param ^. paramName ++ "[] will forward their values in a list to the handler."]
619622 else []) ++
620623 (if (param ^. paramKind == Flag)