From 2779f523caa1155429ab04f99630bfc385512022 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Tue, 7 Nov 2017 18:49:30 +0200 Subject: [PATCH] Add doctests (and changelog) --- servant/CHANGELOG.md | 2 ++ servant/src/Servant/Utils/Links.hs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/servant/CHANGELOG.md b/servant/CHANGELOG.md index 1fe4c8c9..a5603540 100644 --- a/servant/CHANGELOG.md +++ b/servant/CHANGELOG.md @@ -30,6 +30,8 @@ [#767](https://github.com/haskell-servant/servant/pull/767) [#790](https://github.com/haskell-servant/servant/pull/790) [#788](https://github.com/haskell-servant/servant/pull/788)) +- Add `addLinks` to generate all links for unnested APIs. + ([#851](https://github.com/haskell-servant/servant/pull/851)) - Allow newest dependencies ([#772](https://github.com/haskell-servant/servant/pull/772) [#842](https://github.com/haskell-servant/servant/pull/842)) diff --git a/servant/src/Servant/Utils/Links.hs b/servant/src/Servant/Utils/Links.hs index 80f895c8..d39e4a61 100644 --- a/servant/src/Servant/Utils/Links.hs +++ b/servant/src/Servant/Utils/Links.hs @@ -226,6 +226,20 @@ safeLink _ endpoint = toLink endpoint (Link mempty mempty) -- -- Note that the @api@ type must be restricted to the endpoints that have -- valid links to them. +-- +-- >>> type API = "foo" :> Capture "name" Text :> Get '[JSON] Text :<|> "bar" :> Capture "name" Int :> Get '[JSON] Double +-- >>> let fooLink :<|> barLink = allLinks (Proxy :: Proxy API) +-- >>> :t fooLink +-- fooLink :: Text -> Link +-- >>> :t barLink +-- barLink :: Int -> Link +-- +-- Note: nested APIs don't work well with this approach +-- +-- >>> :kind! MkLink (Capture "nest" Char :> (Capture "x" Int :> Get '[JSON] Int :<|> Capture "y" Double :> Get '[JSON] Double)) +-- MkLink (Capture "nest" Char :> (Capture "x" Int :> Get '[JSON] Int :<|> Capture "y" Double :> Get '[JSON] Double)) :: * +-- = Char -> (Int -> Link) :<|> (Double -> Link) +-- allLinks :: forall api. HasLink api => Proxy api @@ -330,3 +344,4 @@ instance HasLink sub => HasLink (AuthProtect tag :> sub) where -- $setup -- >>> import Servant.API +-- >>> import Data.Text (Text)