diff --git a/servant-docs/golden/comprehensive.md b/servant-docs/golden/comprehensive.md index 7d224502..9584d499 100644 --- a/servant-docs/golden/comprehensive.md +++ b/servant-docs/golden/comprehensive.md @@ -52,11 +52,11 @@ ``` -## GET /capture/:foo +## GET /capture/:bar ### Captures: -- *foo*: Capture foo Int +- *bar*: example description ### Response: diff --git a/servant-docs/src/Servant/Docs/Internal.hs b/servant-docs/src/Servant/Docs/Internal.hs index b36ad88b..d19636bf 100644 --- a/servant-docs/src/Servant/Docs/Internal.hs +++ b/servant-docs/src/Servant/Docs/Internal.hs @@ -862,7 +862,7 @@ instance HasDocs EmptyAPI where -- | @"books" :> 'Capture' "isbn" Text@ will appear as -- @/books/:isbn@ in the docs. instance (KnownSymbol sym, ToCapture (Capture sym a), HasDocs api) - => HasDocs (Capture' mods sym a :> api) where + => HasDocs (Capture' '[] sym a :> api) where docsFor Proxy (endpoint, action) = docsFor subApiP (endpoint', action') @@ -874,6 +874,28 @@ instance (KnownSymbol sym, ToCapture (Capture sym a), HasDocs api) endpoint' = over path (\p -> p ++ [":" ++ symbolVal symP]) endpoint symP = Proxy :: Proxy sym +instance (KnownSymbol descr, KnownSymbol sym, HasDocs api) + => HasDocs (Capture' (Description descr ': mods) sym a :> api) where + + docsFor Proxy (endpoint, action) = + docsFor subApiP (endpoint', action') + + where subApiP = Proxy :: Proxy api + + docCapture = DocCapture (symbolVal symP) (symbolVal descrP) + action' = over captures (|> docCapture) action + endpoint' = over path (\p -> p ++ [":" ++ symbolVal symP]) endpoint + descrP = Proxy :: Proxy descr + symP = Proxy :: Proxy sym + +instance {-# OVERLAPPABLE #-} HasDocs (Capture' mods sym a :> api) + => HasDocs (Capture' (mod ': mods) sym a :> api) where + + docsFor Proxy = + docsFor apiP + + where apiP = Proxy :: Proxy (Capture' mods sym a :> api) + -- | @"books" :> 'CaptureAll' "isbn" Text@ will appear as -- @/books/:isbn@ in the docs. diff --git a/servant/src/Servant/Test/ComprehensiveAPI.hs b/servant/src/Servant/Test/ComprehensiveAPI.hs index 2c1b02a3..67417869 100644 --- a/servant/src/Servant/Test/ComprehensiveAPI.hs +++ b/servant/src/Servant/Test/ComprehensiveAPI.hs @@ -48,7 +48,7 @@ comprehensiveAPIWithoutStreaming = Proxy type ComprehensiveAPIWithoutStreamingOrRaw' endpoint = GET :<|> "get-int" :> Get '[JSON] Int - :<|> "capture" :> Capture' '[Description "example description"] "foo" Int :> GET + :<|> "capture" :> Capture' '[Description "example description"] "bar" Int :> GET :<|> "capture-lenient" :> Capture' '[Lenient] "foo" Int :> GET :<|> "header" :> Header "foo" Int :> GET :<|> "header-lenient" :> Header' '[Required, Lenient] "bar" Int :> GET