packages feed

hedgehog-servant 0.0.0.1 → 0.0.1.1

raw patch · 3 files changed

+89/−9 lines, 3 filesdep ~http-clientdep ~servantdep ~servant-clientPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: http-client, servant, servant-client, servant-server

API changes (from Hackage documentation)

Files

+ README.md view
@@ -0,0 +1,44 @@+Hedgehog Servant+================+![](https://github.com/felixmulder/hedgehog-servant/workflows/Haskell%20CI/badge.svg)+![](https://img.shields.io/badge/Hackage-v0.0.0.1-blue.svg)++Hedgehog servant will eat all your servant bugs.++Basic Usage+-----------+Define your servant API endpoints and automatically derive request generators+for them!++This is accomplished using the `genRequest` and the heterogeneous list, called+`GList`, that contains all the generators needed for your API.++So, what do we actually need to do?++1. Define our API (below `SimplestApi`).+2. Define generators for each element that gets captured in the request.+3. Call the function `genRequest` with a proxy for the API (`Proxy+   @SimplestApi`) and all generators needed in a generator list (`GList`)!++In code this looks like:++```haskell+-- POST /cats+type SimplestApi =+  "my" :> "cats" :> ReqBody '[JSON] Cat :> Post '[JSON] ()++-- Generate a request to the Cat API from a base URL+catRequestGen :: BaseUrl -> Gen Request+catRequestGen baseUrl =+  genRequest (Proxy @SimplestApi) (genCat :*: GNil) <&>+    \makeReq -> makeReq baseUrl+```++We construct generator lists with `element1 :*: element2 :*: ... elementN :*: GNil`,+where `GNil` denotes the end of the generator list. The `genRequest` function+will derive a request from the generators in the list. This includes request+bodies, headers and query parameters.++Note: since the generator list may contain many generators for a specific type,+the first one will be chosen. This means that for types that may collide (e.g.+common types like `String`,`Integer` etc), you should define newtype wrappers.
hedgehog-servant.cabal view
@@ -1,7 +1,7 @@ name:   hedgehog-servant version:-  0.0.0.1+  0.0.1.1 synopsis:   Hedgehog property testing for Servant APIs description:@@ -25,6 +25,7 @@ build-type:   Simple extra-source-files:+  README.md   CHANGELOG.md  source-repository head@@ -59,12 +60,12 @@     , bytestring                >= 0.10     && < 0.11     , case-insensitive          >= 1.2      && < 1.3     , hedgehog                  >= 0.6      && < 1.1-    , http-client               >= 0.6      && < 0.7+    , http-client               >= 0.5.14   && < 0.7     , http-media                >= 0.8      && < 0.9     , http-types                >= 0.12     && < 0.13-    , servant                   >= 0.16     && < 0.17-    , servant-client            >= 0.16     && < 0.17-    , servant-server            >= 0.16     && < 0.17+    , servant                   >= 0.16     && < 0.19+    , servant-client            >= 0.16     && < 0.19+    , servant-server            >= 0.16     && < 0.19     , string-conversions        >= 0.4      && < 0.5     , text                      >= 1.2      && < 1.3 @@ -119,11 +120,11 @@     , bytestring                >= 0.10     && < 0.11     , case-insensitive          >= 1.2      && < 1.3     , hedgehog                  >= 0.6      && < 1.1-    , http-client               >= 0.6      && < 0.7+    , http-client               >= 0.5.14   && < 0.7     , http-media                >= 0.8      && < 0.9     , http-types                >= 0.12     && < 0.13-    , servant                   >= 0.16     && < 0.17-    , servant-client            >= 0.16     && < 0.17-    , servant-server            >= 0.16     && < 0.17+    , servant                   >= 0.16     && < 0.19+    , servant-client            >= 0.16     && < 0.19+    , servant-server            >= 0.16     && < 0.19     , string-conversions        >= 0.4      && < 0.5     , text                      >= 1.2      && < 1.3
src/Hedgehog/Servant.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} module Hedgehog.Servant   ( GList(..)   , HasGen(..)@@ -31,6 +32,14 @@ import           Servant.API.ContentTypes (AllMimeRender(..)) import           Servant.Client (BaseUrl(..), Scheme(..)) +#if MIN_VERSION_servant(0, 17, 0)+import           Servant.API (NoContentVerb)+#endif++#if MIN_VERSION_servant(0, 18, 1)+import           Servant.API (UVerb)+#endif+ -- | Data structure used in order to specify generators for API -- -- Example usage:@@ -243,6 +252,32 @@         , secure = baseUrlScheme baseUrl == Https         , method = reflectMethod (Proxy @method)         }++#if MIN_VERSION_servant(0, 17, 0)+instance+  ( ReflectMethod method+  ) => GenRequest (NoContentVerb method) gens where+    genRequest _ _ =+      pure $ \baseUrl -> defaultRequest+        { host = cs . baseUrlHost $ baseUrl+        , port = baseUrlPort baseUrl+        , secure = baseUrlScheme baseUrl == Https+        , method = reflectMethod (Proxy @method)+        }+#endif++#if MIN_VERSION_servant(0, 18, 1)+instance+  ( ReflectMethod method+  ) => GenRequest (UVerb method contentTypes bodies) gens where+    genRequest _ _ =+      pure $ \baseUrl -> defaultRequest+        { host = cs . baseUrlHost $ baseUrl+        , port = baseUrlPort baseUrl+        , secure = baseUrlScheme baseUrl == Https+        , method = reflectMethod (Proxy @method)+        }+#endif  -- | This instance doees not do anything right now --