servant-aeson-specs 0.3 → 0.4
raw patch · 3 files changed
+39/−1 lines, 3 files
Files
- servant-aeson-specs.cabal +1/−1
- src/Servant/Aeson/Internal.hs +18/−0
- test/Servant/Aeson/RoundtripSpecsSpec.hs +20/−0
servant-aeson-specs.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: servant-aeson-specs-version: 0.3+version: 0.4 synopsis: generic tests for aeson serialization in servant description: tests for aeson serialization in servant category: Web
src/Servant/Aeson/Internal.hs view
@@ -59,6 +59,21 @@ collectRoundtripSpecs (Proxy :: Proxy a) ++ collectRoundtripSpecs (Proxy :: Proxy b) +-- * http methods++#if MIN_VERSION_servant(0, 5, 0)+instance {-# OVERLAPPABLE #-}+ (MkTypeSpecs response) =>+ HasGenericSpecs (Verb (method :: StdMethod) returnStatus contentTypes response) where++ collectRoundtripSpecs Proxy = do+ mkTypeSpecs (Proxy :: Proxy response)++instance {-# OVERLAPPING #-}+ HasGenericSpecs (Verb (method :: StdMethod) returnStatus contentTypes NoContent) where++ collectRoundtripSpecs Proxy = []+#else instance (MkTypeSpecs response) => HasGenericSpecs (Get contentTypes response) where @@ -69,6 +84,9 @@ HasGenericSpecs (Post contentTypes response) where collectRoundtripSpecs Proxy = mkTypeSpecs (Proxy :: Proxy response)+#endif++-- * combinators instance (MkTypeSpecs body, HasGenericSpecs api) => HasGenericSpecs (ReqBody contentTypes body :> api) where
test/Servant/Aeson/RoundtripSpecsSpec.hs view
@@ -85,14 +85,22 @@ it "returns types sorted by name" $ do usedTypes reqBodyFailApi `shouldBe` [boolRep, faultyRoundtripRep] + it "works for Post" $ do+ usedTypes postApi `shouldBe` [boolRep]+ matrixParamTest + noContentTest+ reqBodyFailApi :: Proxy (ReqBody '[JSON] FaultyRoundtrip :> Get '[JSON] Bool) reqBodyFailApi = Proxy getFailApi :: Proxy (Get '[JSON] FaultyRoundtrip) getFailApi = Proxy +postApi :: Proxy (Post '[JSON] Bool)+postApi = Proxy+ getListOfBool :: Proxy (Get '[JSON] [Bool]) getListOfBool = Proxy @@ -115,4 +123,16 @@ matrixParamApi = Proxy #else matrixParamTest = return ()+#endif++noContentTest :: Spec+#if MIN_VERSION_servant(0, 5, 0)+noContentTest = do+ it "works for Apis containing NoContent" $ do+ usedTypes noContentApi `shouldBe` [boolRep]++noContentApi :: Proxy (ReqBody '[JSON] Bool :> GetNoContent '[JSON] NoContent)+noContentApi = Proxy+#else+noContentTest = return () #endif