git.iko.soy/typeable/servant
on master help sign in
Add Description and Summary combinators
2e59a82Catherine Galkina
servant/servant.cabal+1
@@ -38,6 +38,7 @@ library
38 Servant.API.BasicAuth
38 Servant.API.BasicAuth
39 Servant.API.Capture
39 Servant.API.Capture
40 Servant.API.ContentTypes
40 Servant.API.ContentTypes
41+ Servant.API.Description
41 Servant.API.Empty
42 Servant.API.Empty
42 Servant.API.Experimental.Auth
43 Servant.API.Experimental.Auth
43 Servant.API.Header
44 Servant.API.Header
servant/src/Servant/API.hs+4
@@ -34,6 +34,9 @@ module Servant.API (
34 -- * Authentication
34 -- * Authentication
35 module Servant.API.BasicAuth,
35 module Servant.API.BasicAuth,
36
36
37+ -- * Endpoints description
38+ module Servant.API.Description,
39+
37 -- * Content Types
40 -- * Content Types
38 module Servant.API.ContentTypes,
41 module Servant.API.ContentTypes,
39 -- | Serializing and deserializing types based on @Accept@ and
42 -- | Serializing and deserializing types based on @Accept@ and
@@ -68,6 +71,7 @@ import Servant.API.ContentTypes (Accept (..), FormUrlEncoded,
68 MimeRender (..), NoContent (NoContent),
71 MimeRender (..), NoContent (NoContent),
69 MimeUnrender (..), OctetStream,
72 MimeUnrender (..), OctetStream,
70 PlainText)
73 PlainText)
74+import Servant.API.Description (Description, Summary)
71import Servant.API.Empty (EmptyAPI (..))
75import Servant.API.Empty (EmptyAPI (..))
72import Servant.API.Experimental.Auth (AuthProtect)
76import Servant.API.Experimental.Auth (AuthProtect)
73import Servant.API.Header (Header (..))
77import 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 =
38 Verb 'POST 204 '[JSON] Int :<|>
38 Verb 'POST 204 '[JSON] Int :<|>
39 WithNamedContext "foo" '[] GET :<|>
39 WithNamedContext "foo" '[] GET :<|>
40 CaptureAll "foo" Int :> GET :<|>
40 CaptureAll "foo" Int :> GET :<|>
41+ Summary "foo" :> GET :<|>
42+ Description "foo" :> GET :<|>
41 EmptyAPI
43 EmptyAPI
42
44
43comprehensiveAPIWithoutRaw :: Proxy ComprehensiveAPIWithoutRaw
45comprehensiveAPIWithoutRaw :: Proxy ComprehensiveAPIWithoutRaw