git.iko.soy/typeable/servant
on master help sign in
Merge pull request #124 from kantp/fix-docswith
74423feAlp Mestanogullari
servant-docs/servant-docs.cabal+1
@@ -70,6 +70,7 @@ test-suite spec
70 base
70 base
71 , aeson
71 , aeson
72 , hspec
72 , hspec
73+ , lens
73 , servant
74 , servant
74 , servant-docs
75 , servant-docs
75 , string-conversions
76 , string-conversions
servant-docs/src/Servant/Docs/Internal.hs+1−1
@@ -338,7 +338,7 @@ extraInfo p action =
338docsWith :: HasDocs layout => [DocIntro] -> ExtraInfo layout -> Proxy layout -> API
338docsWith :: HasDocs layout => [DocIntro] -> ExtraInfo layout -> Proxy layout -> API
339docsWith intros (ExtraInfo endpoints) p =
339docsWith intros (ExtraInfo endpoints) p =
340 docs p & apiIntros <>~ intros
340 docs p & apiIntros <>~ intros
341− & apiEndpoints %~ HM.unionWith combineAction endpoints
341+ & apiEndpoints %~ HM.unionWith (flip combineAction) endpoints
342
342
343
343
344-- | Generate the docs for a given API that implements 'HasDocs' with with any
344-- | Generate the docs for a given API that implements 'HasDocs' with with any
servant-docs/test/Servant/DocsSpec.hs+26−3
@@ -7,7 +7,9 @@
7{-# OPTIONS_GHC -fno-warn-orphans #-}
7{-# OPTIONS_GHC -fno-warn-orphans #-}
8module Servant.DocsSpec where
8module Servant.DocsSpec where
9
9
10+import Control.Lens
10import Data.Aeson
11import Data.Aeson
12+import Data.Monoid
11import Data.Proxy
13import Data.Proxy
12import Data.String.Conversions (cs)
14import Data.String.Conversions (cs)
13import GHC.Generics
15import GHC.Generics
@@ -21,7 +23,27 @@ spec = describe "Servant.Docs" $ do
21
23
22 describe "markdown" $ do
24 describe "markdown" $ do
23 let md = markdown (docs (Proxy :: Proxy TestApi1))
25 let md = markdown (docs (Proxy :: Proxy TestApi1))
24−
26+ tests md
27+
28+ describe "markdown with extra info" $ do
29+ let
30+ extra = extraInfo
31+ (Proxy :: Proxy (Get '[JSON, PlainText] Int))
32+ (defAction & notes <>~ [DocNote "Get an Integer" ["get an integer in Json or plain text"]])
33+ <>
34+ extraInfo
35+ (Proxy :: Proxy (ReqBody '[JSON] String :> Post '[JSON] Datatype1))
36+ (defAction & notes <>~ [DocNote "Post data" ["Posts some Json data"]])
37+ md = markdown (docsWith [] extra (Proxy :: Proxy TestApi1))
38+ tests md
39+ it "contains the extra info provided" $ do
40+ md `shouldContain` "Get an Integer"
41+ md `shouldContain` "Post data"
42+ md `shouldContain` "get an integer in Json or plain text"
43+ md `shouldContain` "Posts some Json data"
44+
45+ where
46+ tests md = do
25 it "mentions supported content-types" $ do
47 it "mentions supported content-types" $ do
26 md `shouldContain` "application/json"
48 md `shouldContain` "application/json"
27 md `shouldContain` "text/plain;charset=utf-8"
49 md `shouldContain` "text/plain;charset=utf-8"
@@ -34,10 +56,11 @@ spec = describe "Servant.Docs" $ do
34 md `shouldContain` "POST"
56 md `shouldContain` "POST"
35 md `shouldContain` "GET"
57 md `shouldContain` "GET"
36
58
37− it "contains response samples" $ do
59+ it "contains response samples" $
38 md `shouldContain` "{\"dt1field1\":\"field 1\",\"dt1field2\":13}"
60 md `shouldContain` "{\"dt1field1\":\"field 1\",\"dt1field2\":13}"
39− it "contains request body samples" $ do
61+ it "contains request body samples" $
40 md `shouldContain` "17"
62 md `shouldContain` "17"
63+
41-- * APIs
64-- * APIs
42
65
43data Datatype1 = Datatype1 { dt1field1 :: String
66data Datatype1 = Datatype1 { dt1field1 :: String