git.iko.soy/typeable/servant
on master help sign in
Add Description and Summary combinators
commit2e59a82d012bf670b015e4ee69efe1e740060a15 authorCatherine Galkina <catherine@getshoptv.com> dateThu 8 Jun 2017, 17:35 (9 years ago) parentbb7df7b
4 files changed+39
servant/servant.cabal+1 servant/src/Servant/API.hs+4 servant/src/Servant/API/Description.hs+32 servant/src/Servant/API/Internal/Test/ComprehensiveAPI.hs+2
servant/servant.cabal+1
@@ -38,6 +38,7 @@ library
3838 Servant.API.BasicAuth
3939 Servant.API.Capture
4040 Servant.API.ContentTypes
41+ Servant.API.Description
4142 Servant.API.Empty
4243 Servant.API.Experimental.Auth
4344 Servant.API.Header
servant/src/Servant/API.hs+4
@@ -34,6 +34,9 @@ module Servant.API (
3434 -- * Authentication
3535 module Servant.API.BasicAuth,
3636
37+ -- * Endpoints description
38+ module Servant.API.Description,
39+
3740 -- * Content Types
3841 module Servant.API.ContentTypes,
3942 -- | Serializing and deserializing types based on @Accept@ and
@@ -68,6 +71,7 @@ import Servant.API.ContentTypes (Accept (..), FormUrlEncoded,
6871 MimeRender (..), NoContent (NoContent),
6972 MimeUnrender (..), OctetStream,
7073 PlainText)
74+import Servant.API.Description (Description, Summary)
7175import Servant.API.Empty (EmptyAPI (..))
7276import Servant.API.Experimental.Auth (AuthProtect)
7377import Servant.API.Header (Header (..))
servant/src/Servant/API/Description.hsnew file+32
@@ -0,0 +1,32 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveDataTypeable #-}
3+{-# LANGUAGE PolyKinds #-}
4+{-# OPTIONS_HADDOCK not-home #-}
5+module Servant.API.Description (Description, Summary) where
6+
7+import Data.Typeable (Typeable)
8+import GHC.TypeLits (Symbol)
9+-- | Add a short summary for (part of) API.
10+--
11+-- Example:
12+--
13+-- >>> type MyApi = Summary "Get book by ISBN." :> "books" :> Capture "isbn" Text :> Get '[JSON] Book
14+data Summary (sym :: Symbol)
15+ deriving (Typeable)
16+
17+-- | Add more verbose description for (part of) API.
18+--
19+-- Example:
20+--
21+-- >>> type MyApi = Description "Some longer implementation details here." :> "books" :> Capture "isbn" Text :> Get '[JSON] Book
22+data Description (sym :: Symbol)
23+ deriving (Typeable)
24+
25+-- $setup
26+-- >>> import Servant.API
27+-- >>> import Data.Aeson
28+-- >>> import Data.Text
29+-- >>> data Book
30+-- >>> instance ToJSON Book where { toJSON = undefined }
31+-- >>> data SourceFile
32+-- >>> instance ToJSON SourceFile where { toJSON = undefined }
servant/src/Servant/API/Internal/Test/ComprehensiveAPI.hs+2
@@ -38,6 +38,8 @@ type ComprehensiveAPIWithoutRaw =
3838 Verb 'POST 204 '[JSON] Int :<|>
3939 WithNamedContext "foo" '[] GET :<|>
4040 CaptureAll "foo" Int :> GET :<|>
41+ Summary "foo" :> GET :<|>
42+ Description "foo" :> GET :<|>
4143 EmptyAPI
4244
4345comprehensiveAPIWithoutRaw :: Proxy ComprehensiveAPIWithoutRaw