packages feed

servant-aeson-specs 0.5.0.0 → 0.5.1.0

raw patch · 3 files changed

+85/−12 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Servant.Aeson.Internal: instance Servant.Aeson.Internal.HasGenericSpecs api => Servant.Aeson.Internal.HasGenericSpecs (Servant.API.Capture.Capture sym x Servant.API.Sub.:> api)
+ Servant.Aeson.Internal: instance Servant.Aeson.Internal.HasGenericSpecs api => Servant.Aeson.Internal.HasGenericSpecs (Servant.API.Experimental.Auth.AuthProtect sym Servant.API.Sub.:> api)
+ Servant.Aeson.Internal: instance Servant.Aeson.Internal.HasGenericSpecs api => Servant.Aeson.Internal.HasGenericSpecs (Servant.API.Header.Header sym x Servant.API.Sub.:> api)
+ Servant.Aeson.Internal: instance Servant.Aeson.Internal.HasGenericSpecs api => Servant.Aeson.Internal.HasGenericSpecs (Servant.API.QueryParam.QueryParam sym x Servant.API.Sub.:> api)
+ Servant.Aeson.Internal: instance Servant.Aeson.Internal.MkTypeSpecs response => Servant.Aeson.Internal.HasGenericSpecs (Servant.API.Verbs.Verb method returnStatus contentTypes (Servant.API.ResponseHeaders.Headers hs response))

Files

servant-aeson-specs.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           servant-aeson-specs-version:        0.5.0.0+version:        0.5.1.0 synopsis:       generic tests for aeson serialization in servant description:    tests for aeson serialization in servant category:       Web
src/Servant/Aeson/Internal.hs view
@@ -86,8 +86,7 @@ -- * http methods  #if MIN_VERSION_servant(0, 5, 0)--- | Servant >= 0.5.0, pattern match on 'StdMethod' and response with content,--- make 'TypeSpec's.+-- | Servant >= 0.5.0, pattern match on 'StdMethod' and response with content. instance {-# OVERLAPPABLE #-}   (MkTypeSpecs response) =>   HasGenericSpecs (Verb (method :: StdMethod) returnStatus contentTypes response) where@@ -95,25 +94,45 @@   collectRoundtripSpecs settings Proxy = do     mkTypeSpecs settings (Proxy :: Proxy response) --- | Servant >= 0.5.0, pattern match on 'StdMethod' and 'NoContent', make--- 'TypeSpec's.+-- | Servant >= 0.5.0, pattern match on 'StdMethod' and 'NoContent'. instance {-# OVERLAPPING #-}   HasGenericSpecs (Verb (method :: StdMethod) returnStatus contentTypes NoContent) where-   collectRoundtripSpecs _ Proxy = []-#else--- | Servant < 0.5.0, match 'Get', make 'TypeSpec's.++-- | Servant >= 0.5.0, pattern match on 'StdMethod' and 'Headers'. instance (MkTypeSpecs response) =>+  HasGenericSpecs (Verb (method :: StdMethod) returnStatus contentTypes (Headers hs response)) where+  collectRoundtripSpecs settings Proxy = mkTypeSpecs settings (Proxy :: Proxy response)++#else+-- | Servant < 0.5.0, match 'Get' with response.+instance {-# OVERLAPPABLE #-}+  (MkTypeSpecs response) =>   HasGenericSpecs (Get contentTypes response) where    collectRoundtripSpecs settings Proxy = do     mkTypeSpecs settings (Proxy :: Proxy response) --- | Servant < 0.5.0, match 'Post', make 'TypeSpec's.-instance (MkTypeSpecs response) =>+-- | Servant < 0.5.0, match 'Post' with response.+instance {-# OVERLAPPABLE #-}+  (MkTypeSpecs response) =>   HasGenericSpecs (Post contentTypes response) where    collectRoundtripSpecs settings Proxy = mkTypeSpecs settings (Proxy :: Proxy response)++-- | Servant < 0.5.0, match 'Get' with 'Headers'.+instance {-# OVERLAPPING #-}+  (MkTypeSpecs response) =>+  HasGenericSpecs (Get contentTypes (Headers hs response)) where++  collectRoundtripSpecs settings Proxy = mkTypeSpecs settings (Proxy :: Proxy response)++-- | Servant < 0.5.0, match 'Post' with 'Headers'.+instance {-# OVERLAPPING #-}+  (MkTypeSpecs response) =>+  HasGenericSpecs (Post contentTypes (Headers hs response)) where++  collectRoundtripSpecs settings Proxy = mkTypeSpecs settings (Proxy :: Proxy response) #endif  -- * combinators@@ -130,7 +149,23 @@ instance HasGenericSpecs api => HasGenericSpecs ((path :: Symbol) :> api) where   collectRoundtripSpecs settings Proxy = collectRoundtripSpecs settings (Proxy :: Proxy api) -#if !MIN_VERSION_servant(0, 5, 0)+-- | Match 'Capture' and ':>'.+instance HasGenericSpecs api  => HasGenericSpecs (Capture (sym :: Symbol) x :> api) where+  collectRoundtripSpecs settings Proxy = collectRoundtripSpecs settings (Proxy :: Proxy api)++-- | Match 'QueryParam' and ':>'.+instance HasGenericSpecs api  => HasGenericSpecs (QueryParam (sym :: Symbol) x :> api) where+  collectRoundtripSpecs settings Proxy = collectRoundtripSpecs settings (Proxy :: Proxy api)++-- | Match 'Header' and ':>'.+instance HasGenericSpecs api  => HasGenericSpecs (Header (sym :: Symbol) x :> api) where+  collectRoundtripSpecs settings Proxy = collectRoundtripSpecs settings (Proxy :: Proxy api)++#if MIN_VERSION_servant(0, 5, 0)+-- | Servant >= 0.5.0, match 'AuthProtect' and ':>'.+instance HasGenericSpecs api => HasGenericSpecs (AuthProtect (sym :: Symbol) :> api) where+  collectRoundtripSpecs settings Proxy = collectRoundtripSpecs settings (Proxy :: Proxy api)+#else -- | Servant < 0.5.0, match 'MatrixParam' and ':>'. instance HasGenericSpecs api => HasGenericSpecs (MatrixParam name a :> api) where   collectRoundtripSpecs settings Proxy = collectRoundtripSpecs settings (Proxy :: Proxy api)
test/Servant/Aeson/RoundtripSpecsSpec.hs view
@@ -91,10 +91,24 @@     it "works for Post" $ do       usedTypes postApi `shouldBe` [boolRep] +    it "ignores response headers" $ do+      usedTypes responseHeadersApi `shouldBe` [boolRep]++    it "traverses Capture" $ do+      usedTypes captureApi `shouldBe` [boolRep]++    it "traverses request headers" $ do+      usedTypes requestHeadersApi `shouldBe` [boolRep]++    it "traverses query params" $ do+      usedTypes queryParamsApi `shouldBe` [boolRep]+     matrixParamTest      noContentTest +    authProtectTest+ reqBodyFailApi :: Proxy (ReqBody '[JSON] FaultyRoundtrip :> Get '[JSON] Bool) reqBodyFailApi = Proxy @@ -116,6 +130,18 @@ boolRep :: TypeRep boolRep = typeRep (Proxy :: Proxy Bool) +responseHeadersApi :: Proxy (Post '[JSON] (Headers '[Header "Cookie" Int] Bool))+responseHeadersApi= Proxy++captureApi :: Proxy (Capture "number" Int :> Post '[JSON] Bool)+captureApi = Proxy++requestHeadersApi  :: Proxy (Header "Cookie" Int :> Post '[JSON] Bool)+requestHeadersApi = Proxy++queryParamsApi :: Proxy (QueryParam "foo" Int :> Post '[JSON] Bool)+queryParamsApi = Proxy+ matrixParamTest :: Spec #if !MIN_VERSION_servant(0, 5, 0) matrixParamTest = do@@ -140,7 +166,6 @@ noContentTest = return () #endif - -- | Type where roundtrips don't work. data FaultyRoundtrip   = FaultyRoundtrip {@@ -159,3 +184,16 @@  instance Arbitrary FaultyRoundtrip where   arbitrary = FaultyRoundtrip <$> arbitrary <*> arbitrary+++authProtectTest :: Spec+#if MIN_VERSION_servant(0, 5, 0)+authProtectTest =  do+  it "traverses AuthProtect" $ do+    usedTypes authProtectApi `shouldBe` [boolRep]++authProtectApi :: Proxy (AuthProtect "scheme" :> Post '[JSON] Bool)+authProtectApi = Proxy+#else+authProtectTest = return ()+#endif