git.iko.soy/typeable/servant
on master help sign in
Re-add missing Header instance for docs.
37afddfJulian K. Arni
servant-docs/src/Servant/Docs/Internal.hs+9
@@ -707,6 +707,15 @@ instance OVERLAPPING_
707 status = fromInteger $ natVal (Proxy :: Proxy status)
707 status = fromInteger $ natVal (Proxy :: Proxy status)
708 p = Proxy :: Proxy a
708 p = Proxy :: Proxy a
709
709
710+instance (KnownSymbol sym, HasDocs sublayout)
711+ => HasDocs (Header sym a :> sublayout) where
712+ docsFor Proxy (endpoint, action) =
713+ docsFor sublayoutP (endpoint, action')
714+
715+ where sublayoutP = Proxy :: Proxy sublayout
716+ action' = over headers (|> headername) action
717+ headername = T.pack $ symbolVal (Proxy :: Proxy sym)
718+
710instance (KnownSymbol sym, ToParam (QueryParam sym a), HasDocs sublayout)
719instance (KnownSymbol sym, ToParam (QueryParam sym a), HasDocs sublayout)
711 => HasDocs (QueryParam sym a :> sublayout) where
720 => HasDocs (QueryParam sym a :> sublayout) where
712
721
servant-docs/test/Servant/DocsSpec.hs+6
@@ -63,6 +63,7 @@ spec = describe "Servant.Docs" $ do
63 , ("zwei, kaks, kaks",(TT2,UT2,UT2))
63 , ("zwei, kaks, kaks",(TT2,UT2,UT2))
64 ]
64 ]
65
65
66+
66 where
67 where
67 tests md = do
68 tests md = do
68 it "mentions supported content-types" $ do
69 it "mentions supported content-types" $ do
@@ -76,11 +77,15 @@ spec = describe "Servant.Docs" $ do
76 md `shouldContain` "POST"
77 md `shouldContain` "POST"
77 md `shouldContain` "GET"
78 md `shouldContain` "GET"
78
79
80+ it "mentions headers" $ do
81+ md `shouldContain` "- This endpoint is sensitive to the value of the **X-Test** HTTP header."
82+
79 it "contains response samples" $
83 it "contains response samples" $
80 md `shouldContain` "{\"dt1field1\":\"field 1\",\"dt1field2\":13}"
84 md `shouldContain` "{\"dt1field1\":\"field 1\",\"dt1field2\":13}"
81 it "contains request body samples" $
85 it "contains request body samples" $
82 md `shouldContain` "17"
86 md `shouldContain` "17"
83
87
88+
84-- * APIs
89-- * APIs
85
90
86data Datatype1 = Datatype1 { dt1field1 :: String
91data Datatype1 = Datatype1 { dt1field1 :: String
@@ -103,6 +108,7 @@ instance MimeRender PlainText Int where
103
108
104type TestApi1 = Get '[JSON, PlainText] (Headers '[Header "Location" String] Int)
109type TestApi1 = Get '[JSON, PlainText] (Headers '[Header "Location" String] Int)
105 :<|> ReqBody '[JSON] String :> Post '[JSON] Datatype1
110 :<|> ReqBody '[JSON] String :> Post '[JSON] Datatype1
111+ :<|> Header "X-Test" Int :> Put '[JSON] Int
106
112
107data TT = TT1 | TT2 deriving (Show, Eq)
113data TT = TT1 | TT2 deriving (Show, Eq)
108data UT = UT1 | UT2 deriving (Show, Eq)
114data UT = UT1 | UT2 deriving (Show, Eq)