git.iko.soy/typeable/servant
on master help sign in
Add instances for new combinators
commitec0431d9308661657bcc97191c039149c2717092 authorCatherine Galkina <catherine@getshoptv.com> dateThu 8 Jun 2017, 18:27 (9 years ago) parent2e59a82
4 files changed+61−1
servant-client/src/Servant/Client.hs+12 servant-docs/src/Servant/Docs/Internal.hs+21 servant-foreign/src/Servant/Foreign/Internal.hs+14 servant-server/src/Servant/Server/Internal.hs+14−1
servant-client/src/Servant/Client.hs+12
@@ -263,6 +263,18 @@ instance HasClient api
263263 clientWithRoute Proxy =
264264 clientWithRoute (Proxy :: Proxy api)
265265
266+-- | Ignore @'Summary'@ in client functions.
267+instance HasClient api => HasClient (Summary desc :> api) where
268+ type Client (Summary desc :> api) = Client api
269+
270+ clientWithRoute _ = clientWithRoute (Proxy :: Proxy api)
271+
272+-- | Ignore @'Description'@ in client functions.
273+instance HasClient api => HasClient (Description desc :> api) where
274+ type Client (Description desc :> api) = Client api
275+
276+ clientWithRoute _ = clientWithRoute (Proxy :: Proxy api)
277+
266278-- | If you use a 'QueryParam' in one of your endpoints in your API,
267279-- the corresponding querying function will automatically take
268280-- an additional argument of the type specified by your 'QueryParam',
servant-docs/src/Servant/Docs/Internal.hs+21
@@ -798,6 +798,27 @@ instance HasDocs Raw where
798798 docsFor _proxy (endpoint, action) _ =
799799 single endpoint action
800800
801+
802+instance (KnownSymbol desc, HasDocs api)
803+ => HasDocs (Description desc :> api) where
804+
805+ docsFor Proxy (endpoint, action) =
806+ docsFor subApiP (endpoint, action')
807+
808+ where subApiP = Proxy :: Proxy api
809+ action' = over notes (|> note) action
810+ note = DocNote (symbolVal (Proxy :: Proxy desc)) []
811+
812+instance (KnownSymbol desc, HasDocs api)
813+ => HasDocs (Summary desc :> api) where
814+
815+ docsFor Proxy (endpoint, action) =
816+ docsFor subApiP (endpoint, action')
817+
818+ where subApiP = Proxy :: Proxy api
819+ action' = over notes (|> note) action
820+ note = DocNote (symbolVal (Proxy :: Proxy desc)) []
821+
801822-- TODO: We use 'AllMimeRender' here because we need to be able to show the
802823-- example data. However, there's no reason to believe that the instances of
803824-- 'AllMimeUnrender' and 'AllMimeRender' actually agree (or to suppose that
servant-foreign/src/Servant/Foreign/Internal.hs+14
@@ -350,6 +350,20 @@ instance HasForeign lang ftype api
350350 foreignFor lang ftype Proxy req =
351351 foreignFor lang ftype (Proxy :: Proxy api) req
352352
353+instance HasForeign lang ftype api
354+ => HasForeign lang ftype (Summary desc :> api) where
355+ type Foreign ftype (Summary desc :> api) = Foreign ftype api
356+
357+ foreignFor lang ftype Proxy req =
358+ foreignFor lang ftype (Proxy :: Proxy api) req
359+
360+instance HasForeign lang ftype api
361+ => HasForeign lang ftype (Description desc :> api) where
362+ type Foreign ftype (Description desc :> api) = Foreign ftype api
363+
364+ foreignFor lang ftype Proxy req =
365+ foreignFor lang ftype (Proxy :: Proxy api) req
366+
353367-- | Utility class used by 'listFromAPI' which computes
354368-- the data needed to generate a function for each endpoint
355369-- and hands it all back in a list.
servant-server/src/Servant/Server/Internal.hs+14−1
@@ -58,7 +58,8 @@ import Servant.API ((:<|>) (..), (:>), BasicAuth, Capt
5858 IsSecure(..), Header, QueryFlag,
5959 QueryParam, QueryParams, Raw,
6060 RemoteHost, ReqBody, Vault,
61− WithNamedContext)
61+ WithNamedContext,
62+ Description, Summary)
6263import Servant.API.ContentTypes (AcceptHeader (..),
6364 AllCTRender (..),
6465 AllCTUnrender (..),
@@ -533,6 +534,18 @@ instance HasServer api context => HasServer (HttpVersion :> api) context where
533534 route Proxy context subserver =
534535 route (Proxy :: Proxy api) context (passToServer subserver httpVersion)
535536
537+-- | Ignore @'Summary'@ in server handlers.
538+instance HasServer api ctx => HasServer (Summary desc :> api) ctx where
539+ type ServerT (Summary desc :> api) m = ServerT api m
540+
541+ route _ = route (Proxy :: Proxy api)
542+
543+-- | Ignore @'Description'@ in server handlers.
544+instance HasServer api ctx => HasServer (Description desc :> api) ctx where
545+ type ServerT (Description desc :> api) m = ServerT api m
546+
547+ route _ = route (Proxy :: Proxy api)
548+
536549-- | Singleton type representing a server that serves an empty API.
537550data EmptyServer = EmptyServer deriving (Typeable, Eq, Show, Bounded, Enum)
538551