From 42fc048dfc57c2a1d41be84dcb1c50e100a63e8a Mon Sep 17 00:00:00 2001 From: Phil Freeman Date: Wed, 31 Dec 2014 17:19:35 -0800 Subject: [PATCH 1/2] Add missing slash character in generated docs. --- src/Servant/Docs.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Servant/Docs.hs b/src/Servant/Docs.hs index a3bcf5ee..3c132ee7 100644 --- a/src/Servant/Docs.hs +++ b/src/Servant/Docs.hs @@ -175,7 +175,7 @@ instance Show Endpoint where -- POST /foo -- @ defEndpoint :: Endpoint -defEndpoint = Endpoint "/" DocGET +defEndpoint = Endpoint "" DocGET instance Hashable Endpoint @@ -577,7 +577,7 @@ instance (KnownSymbol path, HasDocs sublayout) => HasDocs (path :> sublayout) wh docsFor sublayoutP (endpoint', action) where sublayoutP = Proxy :: Proxy sublayout - endpoint' = endpoint & path <>~ symbolVal pa + endpoint' = endpoint & path <>~ '/' : symbolVal pa pa = Proxy :: Proxy path {- From 43f9aa78c0f650cfeba2d54e987bd2d1635f003d Mon Sep 17 00:00:00 2001 From: Phil Freeman Date: Fri, 2 Jan 2015 10:06:34 -0800 Subject: [PATCH 2/2] Represent path as [String] --- src/Servant/Docs.hs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Servant/Docs.hs b/src/Servant/Docs.hs index 3c132ee7..606ac9da 100644 --- a/src/Servant/Docs.hs +++ b/src/Servant/Docs.hs @@ -148,19 +148,26 @@ instance Hashable Method -- @ -- λ> 'defEndpoint' -- GET / --- λ> 'defEndpoint' & 'path' '<>~' "foo" +-- λ> 'defEndpoint' & 'path' '<>~' ["foo"] -- GET /foo --- λ> 'defEndpoint' & 'path' '<>~' "foo" & 'method' '.~' 'DocPOST' +-- λ> 'defEndpoint' & 'path' '<>~' ["foo"] & 'method' '.~' 'DocPOST' -- POST /foo -- @ data Endpoint = Endpoint - { _path :: String -- type collected - , _method :: Method -- type collected + { _path :: [String] -- type collected + , _method :: Method -- type collected } deriving (Eq, Generic) instance Show Endpoint where show (Endpoint p m) = - show m ++ " " ++ p + show m ++ " " ++ showPath p + +-- | +-- Render a path as a '/'-delimited string +-- +showPath :: [String] -> String +showPath [] = "/" +showPath ps = concatMap ('/' :) ps -- | An 'Endpoint' whose path is `"/"` and whose method is 'DocGET' -- @@ -169,13 +176,13 @@ instance Show Endpoint where -- @ -- λ> 'defEndpoint' -- GET / --- λ> 'defEndpoint' & 'path' '<>~' "foo" +-- λ> 'defEndpoint' & 'path' '<>~' ["foo"] -- GET /foo --- λ> 'defEndpoint' & 'path' '<>~' "foo" & 'method' '.~' 'DocPOST' +-- λ> 'defEndpoint' & 'path' '<>~' ["foo"] & 'method' '.~' 'DocPOST' -- POST /foo -- @ defEndpoint :: Endpoint -defEndpoint = Endpoint "" DocGET +defEndpoint = Endpoint [] DocGET instance Hashable Endpoint @@ -376,7 +383,7 @@ markdown = unlines . concat . map (uncurry printEndpoint) . HM.toList responseStr (action ^. response) ++ [] - where str = show (endpoint^.method) ++ " " ++ endpoint^.path + where str = show (endpoint^.method) ++ " " ++ showPath (endpoint^.path) len = length str capturesStr :: [DocCapture] -> [String] @@ -472,7 +479,7 @@ instance (KnownSymbol sym, ToCapture (Capture sym a), HasDocs sublayout) captureP = Proxy :: Proxy (Capture sym a) action' = over captures (|> toCapture captureP) action - endpoint' = over path (\p -> p++"/:"++symbolVal symP) endpoint + endpoint' = over path (\p -> p ++ [":" ++ symbolVal symP]) endpoint symP = Proxy :: Proxy sym @@ -577,7 +584,7 @@ instance (KnownSymbol path, HasDocs sublayout) => HasDocs (path :> sublayout) wh docsFor sublayoutP (endpoint', action) where sublayoutP = Proxy :: Proxy sublayout - endpoint' = endpoint & path <>~ '/' : symbolVal pa + endpoint' = endpoint & path <>~ [symbolVal pa] pa = Proxy :: Proxy path {-