on master help sign in
Merge pull request #196 from haskell-servant/jkarni/contributing

'Contributing' section in the README + stylish haskell changes

commit90d837dda9fde994332302952364f00d5666dbab authorAlp Mestanogullari <alpmestan@gmail.com> dateTue 18 Aug 2015, 11:25 (11 years ago) parent1a27e466eb7add
68 files changed+562−462
.stylish-haskell.yaml+77 HLint.hs+6 README.md+46−7 servant-blaze/Setup.hs+1−1 servant-client/Setup.hs+1−1 servant-client/src/Servant/Common/BaseUrl.hs+9−9 servant-client/src/Servant/Common/Req.hs+1−1 servant-client/test/Servant/Common/BaseUrlSpec.hs+6−6 servant-client/test/Spec.hs+1−1 servant-docs/Setup.hs+1−1 servant-docs/src/Servant/Docs.hs+1−1 servant-docs/src/Servant/Docs/Internal.hs+2−2 servant-examples/Setup.hs+1−1 servant-examples/auth-combinator/auth-combinator.hs+15−15 servant-examples/hackage/hackage.hs+17−17 servant-examples/socket-io-chat/socket-io-chat.hs+12−12 servant-examples/tutorial/T1.hs+11−11 servant-examples/tutorial/T10.hs+12−12 servant-examples/tutorial/T2.hs+10−10 servant-examples/tutorial/T3.hs+14−14 servant-examples/tutorial/T4.hs+11−11 servant-examples/tutorial/T5.hs+11−11 servant-examples/tutorial/T6.hs+4−4 servant-examples/tutorial/T7.hs+6−6 servant-examples/tutorial/T8.hs+7−7 servant-examples/tutorial/T9.hs+14−14 servant-examples/tutorial/t8-main.hs+1−1 servant-examples/tutorial/tutorial.hs+4−4 servant-examples/wai-middleware/wai-middleware.hs+9−9 servant-js/Setup.hs+1−1 servant-js/examples/counter.hs+17−17 servant-js/src/Servant/JS.hs+11−11 servant-js/src/Servant/JS/Angular.hs+13−13 servant-js/src/Servant/JS/Axios.hs+12−12 servant-js/src/Servant/JS/Internal.hs+6−6 servant-js/src/Servant/JS/JQuery.hs+8−8 servant-js/src/Servant/JS/Vanilla.hs+10−10 servant-js/test/Servant/JSSpec.hs+22−22 servant-js/test/Servant/JSSpec/CustomHeaders.hs+7−7 servant-lucid/Setup.hs+1−1 servant-mock/Setup.hs+1−1 servant-mock/example/main.hs+9−9 servant-mock/src/Servant/Mock.hs+18−18 servant-server/Setup.hs+1−1 servant-server/example/greet.hs+15−15 servant-server/src/Servant.hs+6−6 servant-server/src/Servant/Server.hs+2−2 servant-server/src/Servant/Server/Internal.hs+4−6 servant-server/src/Servant/Server/Internal/PathInfo.hs+5−5 servant-server/src/Servant/Server/Internal/Router.hs+5−5 servant-server/src/Servant/Server/Internal/RoutingApplication.hs+17−16 servant-server/src/Servant/Server/Internal/ServantErr.hs+4−4 servant-server/src/Servant/Utils/StaticFiles.hs+6−5 servant-server/test/Doctests.hs+1−1 servant-server/test/Servant/Server/Internal/EnterSpec.hs+4−4 servant-server/test/Servant/Utils/StaticFilesSpec.hs+20−18 servant/Setup.hs+1−1 servant/default.nix−24 servant/src/Servant/API.hs+2−2 servant/src/Servant/API/Delete.hs+1−1 servant/src/Servant/API/HttpVersion.hs+1−1 servant/src/Servant/API/IsSecure.hs+1−1 servant/src/Servant/API/Put.hs+1−1 servant/src/Servant/API/Raw.hs+1−1 servant/src/Servant/API/RemoteHost.hs+1−1 servant/src/Servant/API/Vault.hs+1−1 servant/test/Doctests.hs+1−1 servant/test/Servant/API/ContentTypesSpec.hs+14−14
.stylish-haskell.yamlnew file+77
@@ -0,0 +1,77 @@
1+# stylish-haskell configuration file
2+# ==================================
3+
4+# The stylish-haskell tool is mainly configured by specifying steps. These steps
5+# are a list, so they have an order, and one specific step may appear more than
6+# once (if needed). Each file is processed by these steps in the given order.
7+steps:
8+ # Convert some ASCII sequences to their Unicode equivalents. This is disabled
9+ # by default.
10+ # - unicode_syntax:
11+ # # In order to make this work, we also need to insert the UnicodeSyntax
12+ # # language pragma. If this flag is set to true, we insert it when it's
13+ # # not already present. You may want to disable it if you configure
14+ # # language extensions using some other method than pragmas. Default:
15+ # # true.
16+ # add_language_pragma: true
17+
18+ # Import cleanup
19+ - imports:
20+ # There are different ways we can align names and lists.
21+ #
22+ # - global: Align the import names and import list throughout the entire
23+ # file.
24+ #
25+ # - file: Like global, but don't add padding when there are no qualified
26+ # imports in the file.
27+ #
28+ # - group: Only align the imports per group (a group is formed by adjacent
29+ # import lines).
30+ #
31+ # - none: Do not perform any alignment.
32+ #
33+ # Default: global.
34+ align: global
35+
36+ # Language pragmas
37+ - language_pragmas:
38+ # We can generate different styles of language pragma lists.
39+ #
40+ # - vertical: Vertical-spaced language pragmas, one per line.
41+ #
42+ # - compact: A more compact style.
43+ #
44+ # - compact_line: Similar to compact, but wrap each line with
45+ # `{-#LANGUAGE #-}'.
46+ #
47+ # Default: vertical.
48+ style: vertical
49+
50+ # stylish-haskell can detect redundancy of some language pragmas. If this
51+ # is set to true, it will remove those redundant pragmas. Default: true.
52+ remove_redundant: true
53+
54+ # Align the types in record declarations
55+ - records: {}
56+
57+ # Replace tabs by spaces. This is disabled by default.
58+ # - tabs:
59+ # # Number of spaces to use for each tab. Default: 8, as specified by the
60+ # # Haskell report.
61+ # spaces: 8
62+
63+ # Remove trailing whitespace
64+ - trailing_whitespace: {}
65+
66+# A common setting is the number of columns (parts of) code will be wrapped
67+# to. Different steps take this into account. Default: 80.
68+columns: 80
69+
70+# Sometimes, language extensions are specified in a cabal file or from the
71+# command line instead of using language pragmas in the file. stylish-haskell
72+# needs to be aware of these, so it can parse the file correctly.
73+#
74+# No language extensions are enabled by default.
75+language_extensions:
76+ - TemplateHaskell
77+ - QuasiQuotes
HLint.hsnew file+6
@@ -0,0 +1,6 @@
1+import "hint" HLint.Default
2+
3+ignore "Redundant do"
4+ignore "Parse error"
5+ignore "Use list comprehension"
6+ignore "Use liftM"
README.md+46−7
@@ -5,17 +5,56 @@
55
66![servant](https://raw.githubusercontent.com/haskell-servant/servant/master/servant.png)
77
8−These libraries provides a family of combinators to define webservices and automatically generate the documentation and client-side querying functions for each endpoint.
8+These libraries provides a family of combinators to define webservices and
9+automatically generate the documentation and client-side querying functions for
10+each endpoint.
911
10−In order to minimize the dependencies depending on your needs, we provide these features under different packages.
12+In order to minimize the dependencies depending on your needs, we provide these
13+features under different packages.
1114
1215- `servant`, which contains everything you need to *declare* a webservice API.
13−- `servant-server`, which lets you *implement* an HTTP server with handlers for each endpoint of an API.
14−- `servant-client`, which lets you derive automatically Haskell functions that let you query each endpoint of a `servant` webservice.
16+- `servant-server`, which lets you *implement* an HTTP server with handlers for
17+each endpoint of an API.
18+- `servant-client`, which lets you derive automatically Haskell functions that
19+let you query each endpoint of a `servant` webservice.
1520- `servant-docs`, which lets you generate API docs for your webservice.
16−- `servant-js`, which lets you derive Javascript functions (using vanilla JS ajax requests, angular or jquery) to query your API's endpoints, in the same spirit as `servant-client`.
17−- `servant-blaze` and `servant-lucid` provide easy HTML rendering of your data as an `HTML` content-type "combinator".
21+- `servant-js`, which lets you derive Javascript functions (using vanilla JS
22+ajax requests, angular or jquery) to query your API's endpoints, in the same
23+spirit as `servant-client`.
24+- `servant-blaze` and `servant-lucid` provide easy HTML rendering of your data
25+as an `HTML` content-type "combinator".
1826
1927## Tutorial
2028
21−We have a [tutorial](http://haskell-servant.github.io/tutorial) guide that introduces the core types and features of servant. After this article, you should be able to write your first servant webservices, learning the rest from the haddocks' examples.
29+We have a [tutorial](http://haskell-servant.github.io/tutorial) guide that
30+introduces the core types and features of servant. After this article, you
31+should be able to write your first servant webservices, learning the rest from
32+the haddocks' examples.
33+
34+## Contributing
35+
36+Contributions are very welcome! To hack on the github version, clone the
37+repository. You can use `cabal`:
38+
39+```shell
40+./scripts/start-sandbox.sh # Initialize the sandbox and add-source the packages
41+./scripts/test-all.sh # Run all the tests
42+```
43+
44+`stack`:
45+
46+```shell
47+stack build # Install and build packages
48+stack test # Run all the tests
49+```
50+
51+Or `nix`:
52+```shell
53+./scripts/update-nix-files.sh # Get up-to-date shell.nix files
54+```
55+
56+Though we aren't sticklers for style, the `.stylish-haskel.yaml` and `HLint.hs`
57+files in the repository provide a good baseline for consistency.
58+
59+Please include a description of the changes in your PR in the `CHANGELOG.md` of
60+the packages you've changed. And of course, write tests!
servant-blaze/Setup.hs+1−1
@@ -1,2 +1,2 @@
1−import Distribution.Simple
1+import Distribution.Simple
22main = defaultMain
servant-client/Setup.hs+1−1
@@ -1,2 +1,2 @@
1−import Distribution.Simple
1+import Distribution.Simple
22main = defaultMain
servant-client/src/Servant/Common/BaseUrl.hs+9−9
@@ -11,13 +11,13 @@ module Servant.Common.BaseUrl (
1111 , showBaseUrl
1212) where
1313
14−import Control.Monad.Catch (MonadThrow, throwM, Exception)
15−import Data.List
16−import Data.Typeable
17−import GHC.Generics
18−import Network.URI
19−import Safe
20−import Text.Read
14+import Control.Monad.Catch (Exception, MonadThrow, throwM)
15+import Data.List
16+import Data.Typeable
17+import GHC.Generics
18+import Network.URI
19+import Safe
20+import Text.Read
2121
2222-- | URI scheme to use
2323data Scheme =
@@ -29,8 +29,8 @@ data Scheme =
2929-- for servant's automatically-generated clients.
3030data BaseUrl = BaseUrl
3131 { baseUrlScheme :: Scheme -- ^ URI scheme to use
32− , baseUrlHost :: String -- ^ host (eg "haskell.org")
33− , baseUrlPort :: Int -- ^ port (eg 80)
32+ , baseUrlHost :: String -- ^ host (eg "haskell.org")
33+ , baseUrlPort :: Int -- ^ port (eg 80)
3434 } deriving (Show, Eq, Ord, Generic)
3535
3636showBaseUrl :: BaseUrl -> String
servant-client/src/Servant/Common/Req.hs+1−1
@@ -99,7 +99,7 @@ setRQBody b t req = req { reqBody = Just (b, t) }
9999
100100reqToRequest :: (Functor m, MonadThrow m) => Req -> BaseUrl -> m Request
101101reqToRequest req (BaseUrl reqScheme reqHost reqPort) =
102− fmap (setheaders . setAccept . setrqb . setQS ) $ parseUrl url
102+ setheaders . setAccept . setrqb . setQS <$> parseUrl url
103103
104104 where url = show $ nullURI { uriScheme = case reqScheme of
105105 Http -> "http:"
servant-client/test/Servant/Common/BaseUrlSpec.hs+6−6
@@ -1,15 +1,15 @@
1−{-# LANGUAGE CPP #-}
1+{-# LANGUAGE CPP #-}
22{-# OPTIONS_GHC -fno-warn-orphans #-}
33module Servant.Common.BaseUrlSpec where
44
55#if !MIN_VERSION_base(4,8,0)
6−import Control.Applicative
6+import Control.Applicative
77#endif
8−import Control.DeepSeq
9−import Test.Hspec
10−import Test.QuickCheck
8+import Control.DeepSeq
9+import Test.Hspec
10+import Test.QuickCheck
1111
12−import Servant.Common.BaseUrl
12+import Servant.Common.BaseUrl
1313
1414spec :: Spec
1515spec = do
servant-client/test/Spec.hs+1−1
@@ -1,4 +1,4 @@
1−import Servant.ClientSpec (spec, failSpec)
1+import Servant.ClientSpec (failSpec, spec)
22
33main :: IO ()
44main = do
servant-docs/Setup.hs+1−1
@@ -1,2 +1,2 @@
1−import Distribution.Simple
1+import Distribution.Simple
22main = defaultMain
servant-docs/src/Servant/Docs.hs+1−1
@@ -166,4 +166,4 @@ module Servant.Docs
166166 , single
167167 ) where
168168
169−import Servant.Docs.Internal
169+import Servant.Docs.Internal
servant-docs/src/Servant/Docs/Internal.hs+2−2
@@ -1,5 +1,5 @@
1−{-# LANGUAGE ConstraintKinds #-}
21{-# LANGUAGE CPP #-}
2+{-# LANGUAGE ConstraintKinds #-}
33{-# LANGUAGE DataKinds #-}
44{-# LANGUAGE DeriveGeneric #-}
55{-# LANGUAGE FlexibleContexts #-}
@@ -23,6 +23,7 @@ module Servant.Docs.Internal where
2323import Control.Applicative
2424#endif
2525import Control.Lens
26+import Data.ByteString.Conversion (ToByteString, toByteString)
2627import Data.ByteString.Lazy.Char8 (ByteString)
2728import qualified Data.CaseInsensitive as CI
2829import Data.Hashable
@@ -32,7 +33,6 @@ import Data.Maybe
3233import Data.Monoid
3334import Data.Ord (comparing)
3435import Data.Proxy
35−import Data.ByteString.Conversion (ToByteString, toByteString)
3636import Data.String.Conversions
3737import Data.Text (Text, pack, unpack)
3838import GHC.Exts (Constraint)
servant-examples/Setup.hs+1−1
@@ -1,2 +1,2 @@
1−import Distribution.Simple
1+import Distribution.Simple
22main = defaultMain
servant-examples/auth-combinator/auth-combinator.hs+15−15
@@ -1,19 +1,19 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeFamilies #-}
3−{-# LANGUAGE DeriveGeneric #-}
4−{-# LANGUAGE TypeOperators #-}
5−{-# LANGUAGE FlexibleInstances #-}
6−{-# LANGUAGE OverloadedStrings #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE OverloadedStrings #-}
75{-# LANGUAGE ScopedTypeVariables #-}
8−import Data.Aeson
9−import Data.ByteString (ByteString)
10−import Data.Text (Text)
11−import GHC.Generics
12−import Network.HTTP.Types
13−import Network.Wai
14−import Network.Wai.Handler.Warp
15−import Servant
16−import Servant.Server.Internal
6+{-# LANGUAGE TypeFamilies #-}
7+{-# LANGUAGE TypeOperators #-}
8+import Data.Aeson
9+import Data.ByteString (ByteString)
10+import Data.Text (Text)
11+import GHC.Generics
12+import Network.HTTP.Types
13+import Network.Wai
14+import Network.Wai.Handler.Warp
15+import Servant
16+import Servant.Server.Internal
1717
1818-- Pretty much stolen/adapted from
1919-- https://github.com/haskell-servant/HaskellSGMeetup2015/blob/master/examples/authentication-combinator/AuthenticationCombinator.hs
servant-examples/hackage/hackage.hs+17−17
@@ -1,21 +1,21 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE DeriveGeneric #-}
3−{-# LANGUAGE TypeOperators #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveGeneric #-}
43{-# LANGUAGE OverloadedStrings #-}
5−import Control.Applicative
6−import Control.Monad
7−import Control.Monad.IO.Class
8−import Control.Monad.Trans.Either
9−import Data.Aeson
10−import Data.Monoid
11−import Data.Proxy
12−import Data.Text (Text)
13−import GHC.Generics
14−import Servant.API
15−import Servant.Client
16−
17−import qualified Data.Text as T
18−import qualified Data.Text.IO as T
4+{-# LANGUAGE TypeOperators #-}
5+import Control.Applicative
6+import Control.Monad
7+import Control.Monad.IO.Class
8+import Control.Monad.Trans.Either
9+import Data.Aeson
10+import Data.Monoid
11+import Data.Proxy
12+import Data.Text (Text)
13+import GHC.Generics
14+import Servant.API
15+import Servant.Client
16+
17+import qualified Data.Text as T
18+import qualified Data.Text.IO as T
1919
2020type HackageAPI =
2121 "users" :> Get '[JSON] [UserSummary]
servant-examples/socket-io-chat/socket-io-chat.hs+12−12
@@ -1,24 +1,24 @@
1−{-# LANGUAGE CPP #-}
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DataKinds #-}
23{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE DataKinds #-}
4−{-# LANGUAGE TypeOperators #-}
4+{-# LANGUAGE TypeOperators #-}
55
66
7−import Data.Monoid ((<>))
7+import Data.Monoid ((<>))
88#if !MIN_VERSION_base(4,8,0)
9−import Control.Applicative((<$>))
9+import Control.Applicative ((<$>))
1010#endif
11−import Network.Wai
12−import Servant
13−import Network.EngineIO.Wai
14−import Network.Wai.Handler.Warp (run)
11+import Network.EngineIO.Wai
12+import Network.Wai
13+import Network.Wai.Handler.Warp (run)
14+import Servant
1515
1616
17−import qualified Control.Concurrent.STM as STM
18−import qualified Network.SocketIO as SocketIO
17+import qualified Control.Concurrent.STM as STM
18+import qualified Network.SocketIO as SocketIO
1919
2020
21−import Chat (eioServer, ServerState (..))
21+import Chat (ServerState (..), eioServer)
2222
2323
2424type API = "socket.io" :> Raw
servant-examples/tutorial/T1.hs+11−11
@@ -1,19 +1,19 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeFamilies #-}
1+{-# LANGUAGE DataKinds #-}
32{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE TypeFamilies #-}
44{-# LANGUAGE TypeOperators #-}
55module T1 where
66
7−import Data.Aeson
8−import Data.Time.Calendar
9−import GHC.Generics
10−import Network.Wai
11−import Servant
7+import Data.Aeson
8+import Data.Time.Calendar
9+import GHC.Generics
10+import Network.Wai
11+import Servant
1212
1313data User = User
14− { name :: String
15− , age :: Int
16− , email :: String
14+ { name :: String
15+ , age :: Int
16+ , email :: String
1717 , registration_date :: Day
1818 } deriving (Eq, Show, Generic)
1919
@@ -27,7 +27,7 @@ instance ToJSON User
2727type UserAPI = "users" :> Get '[JSON] [User]
2828
2929users :: [User]
30−users =
30+users =
3131 [ User "Isaac Newton" 372 "isaac@newton.co.uk" (fromGregorian 1683 3 1)
3232 , User "Albert Einstein" 136 "ae@mc2.org" (fromGregorian 1905 12 1)
3333 ]
servant-examples/tutorial/T10.hs+12−12
@@ -1,18 +1,18 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeFamilies #-}
3−{-# LANGUAGE TypeOperators #-}
4−{-# LANGUAGE FlexibleInstances #-}
5−{-# LANGUAGE OverloadedStrings #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE FlexibleInstances #-}
63{-# LANGUAGE MultiParamTypeClasses #-}
4+{-# LANGUAGE OverloadedStrings #-}
5+{-# LANGUAGE TypeFamilies #-}
6+{-# LANGUAGE TypeOperators #-}
77module T10 where
88
9−import Data.ByteString.Lazy (ByteString)
10−import Data.Text.Lazy (pack)
11−import Data.Text.Lazy.Encoding (encodeUtf8)
12−import Network.HTTP.Types
13−import Network.Wai
14−import Servant
15−import Servant.Docs
9+import Data.ByteString.Lazy (ByteString)
10+import Data.Text.Lazy (pack)
11+import Data.Text.Lazy.Encoding (encodeUtf8)
12+import Network.HTTP.Types
13+import Network.Wai
14+import Servant
15+import Servant.Docs
1616import qualified T3
1717
1818type DocsAPI = T3.API :<|> Raw
servant-examples/tutorial/T2.hs+10−10
@@ -1,19 +1,19 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeFamilies #-}
1+{-# LANGUAGE DataKinds #-}
32{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE TypeFamilies #-}
44{-# LANGUAGE TypeOperators #-}
55module T2 where
66
7−import Data.Aeson
8−import Data.Time.Calendar
9−import GHC.Generics
10−import Network.Wai
11−import Servant
7+import Data.Aeson
8+import Data.Time.Calendar
9+import GHC.Generics
10+import Network.Wai
11+import Servant
1212
1313data User = User
14− { name :: String
15− , age :: Int
16− , email :: String
14+ { name :: String
15+ , age :: Int
16+ , email :: String
1717 , registration_date :: Day
1818 } deriving (Eq, Show, Generic)
1919
servant-examples/tutorial/T3.hs+14−14
@@ -1,15 +1,15 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeFamilies #-}
1+{-# LANGUAGE DataKinds #-}
32{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE TypeFamilies #-}
44{-# LANGUAGE TypeOperators #-}
55module T3 where
66
7−import Control.Monad.Trans.Either
8−import Data.Aeson
9−import Data.List
10−import GHC.Generics
11−import Network.Wai
12−import Servant
7+import Control.Monad.Trans.Either
8+import Data.Aeson
9+import Data.List
10+import GHC.Generics
11+import Network.Wai
12+import Servant
1313
1414data Position = Position
1515 { x :: Int
@@ -26,9 +26,9 @@ instance FromJSON HelloMessage
2626instance ToJSON HelloMessage
2727
2828data ClientInfo = ClientInfo
29− { name :: String
30− , email :: String
31− , age :: Int
29+ { name :: String
30+ , email :: String
31+ , age :: Int
3232 , interested_in :: [String]
3333 } deriving (Show, Generic)
3434
@@ -36,10 +36,10 @@ instance FromJSON ClientInfo
3636instance ToJSON ClientInfo
3737
3838data Email = Email
39− { from :: String
40− , to :: String
39+ { from :: String
40+ , to :: String
4141 , subject :: String
42− , body :: String
42+ , body :: String
4343 } deriving (Show, Generic)
4444
4545instance FromJSON Email
servant-examples/tutorial/T4.hs+11−11
@@ -1,18 +1,18 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeFamilies #-}
3−{-# LANGUAGE DeriveGeneric #-}
4−{-# LANGUAGE TypeOperators #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveGeneric #-}
53{-# LANGUAGE FlexibleInstances #-}
64{-# LANGUAGE OverloadedStrings #-}
5+{-# LANGUAGE TypeFamilies #-}
6+{-# LANGUAGE TypeOperators #-}
77module T4 where
88
9−import Data.Aeson
10−import Data.Foldable (foldMap)
11−import GHC.Generics
12−import Lucid
13−import Network.Wai
14−import Servant
15−import Servant.HTML.Lucid
9+import Data.Aeson
10+import Data.Foldable (foldMap)
11+import GHC.Generics
12+import Lucid
13+import Network.Wai
14+import Servant
15+import Servant.HTML.Lucid
1616
1717data Person = Person
1818 { firstName :: String
servant-examples/tutorial/T5.hs+11−11
@@ -1,17 +1,17 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeFamilies #-}
3−{-# LANGUAGE DeriveGeneric #-}
4−{-# LANGUAGE TypeOperators #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveGeneric #-}
53{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE TypeOperators #-}
66module T5 where
77
8−import Control.Monad.IO.Class
9−import Control.Monad.Trans.Either
10−import Data.Aeson
11−import GHC.Generics
12−import Network.Wai
13−import Servant
14−import System.Directory
8+import Control.Monad.IO.Class
9+import Control.Monad.Trans.Either
10+import Data.Aeson
11+import GHC.Generics
12+import Network.Wai
13+import Servant
14+import System.Directory
1515
1616type IOAPI = "myfile.txt" :> Get '[JSON] FileContent
1717
servant-examples/tutorial/T6.hs+4−4
@@ -1,10 +1,10 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeFamilies #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE TypeFamilies #-}
33{-# LANGUAGE TypeOperators #-}
44module T6 where
55
6−import Network.Wai
7−import Servant
6+import Network.Wai
7+import Servant
88
99type API = "code" :> Raw
1010
servant-examples/tutorial/T7.hs+6−6
@@ -1,12 +1,12 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeFamilies #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE TypeFamilies #-}
33{-# LANGUAGE TypeOperators #-}
44module T7 where
55
6−import Control.Monad.Trans.Either
7−import Control.Monad.Trans.Reader
8−import Network.Wai
9−import Servant
6+import Control.Monad.Trans.Either
7+import Control.Monad.Trans.Reader
8+import Network.Wai
9+import Servant
1010
1111type ReaderAPI = "a" :> Get '[JSON] Int
1212 :<|> "b" :> Get '[JSON] String
servant-examples/tutorial/T8.hs+7−7
@@ -1,14 +1,14 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeFamilies #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE TypeFamilies #-}
33{-# LANGUAGE TypeOperators #-}
44module T8 where
55
6−import Control.Monad.Trans.Either
7−import Data.Aeson
8−import Servant
9−import Servant.Client
6+import Control.Monad.Trans.Either
7+import Data.Aeson
8+import Servant
9+import Servant.Client
1010
11−import T3
11+import T3
1212
1313position :: Int -- ^ value for "x"
1414 -> Int -- ^ value for "y"
servant-examples/tutorial/T9.hs+14−14
@@ -1,20 +1,20 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeFamilies #-}
3−{-# LANGUAGE DeriveGeneric #-}
4−{-# LANGUAGE TypeOperators #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveGeneric #-}
53{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE TypeOperators #-}
66module T9 where
77
8−import Control.Applicative
9−import Control.Monad.IO.Class
10−import Data.Aeson
11−import Data.Text (Text)
12−import GHC.Generics
13−import Network.Wai
14−import Servant
15−import Servant.JS
16−import Servant.JS.JQuery
17−import System.Random
8+import Control.Applicative
9+import Control.Monad.IO.Class
10+import Data.Aeson
11+import Data.Text (Text)
12+import GHC.Generics
13+import Network.Wai
14+import Servant
15+import Servant.JS
16+import Servant.JS.JQuery
17+import System.Random
1818
1919import qualified Data.Text as T
2020import qualified Language.Javascript.JQuery as JQ
servant-examples/tutorial/t8-main.hs+1−1
@@ -1,4 +1,4 @@
1−import T8
1+import T8
22
33main :: IO ()
44main = run
servant-examples/tutorial/tutorial.hs+4−4
@@ -1,8 +1,9 @@
1−import Network.Wai
2−import Network.Wai.Handler.Warp
3−import System.Environment
1+import Network.Wai
2+import Network.Wai.Handler.Warp
3+import System.Environment
44
55import qualified T1
6+import qualified T10
67import qualified T2
78import qualified T3
89import qualified T4
@@ -10,7 +11,6 @@ import qualified T5
1011import qualified T6
1112import qualified T7
1213import qualified T9
13−import qualified T10
1414
1515app :: String -> (Application -> IO ()) -> IO ()
1616app n f = case n of
servant-examples/wai-middleware/wai-middleware.hs+9−9
@@ -1,13 +1,13 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE DeriveGeneric #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveGeneric #-}
33{-# LANGUAGE OverloadedStrings #-}
4−import Data.Aeson
5−import Data.Text
6−import GHC.Generics
7−import Network.Wai
8−import Network.Wai.Handler.Warp
9−import Network.Wai.Middleware.RequestLogger
10−import Servant
4+import Data.Aeson
5+import Data.Text
6+import GHC.Generics
7+import Network.Wai
8+import Network.Wai.Handler.Warp
9+import Network.Wai.Middleware.RequestLogger
10+import Servant
1111
1212data Product = Product
1313 { name :: Text
servant-js/Setup.hs+1−1
@@ -1,2 +1,2 @@
1−import Distribution.Simple
1+import Distribution.Simple
22main = defaultMain
servant-js/examples/counter.hs+17−17
@@ -1,19 +1,19 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeOperators #-}
3−{-# LANGUAGE DeriveGeneric #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveGeneric #-}
43{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5−
6−import Control.Concurrent.STM
7−import Control.Monad.IO.Class
8−import Data.Aeson
9−import Data.Proxy
10−import GHC.Generics
11−import Network.Wai.Handler.Warp (run)
12−import Servant
13−import Servant.JS
14−import qualified Servant.JS as SJS
15−import qualified Servant.JS.Angular as NG
16−import System.FilePath
4+{-# LANGUAGE TypeOperators #-}
5+
6+import Control.Concurrent.STM
7+import Control.Monad.IO.Class
8+import Data.Aeson
9+import Data.Proxy
10+import GHC.Generics
11+import Network.Wai.Handler.Warp (run)
12+import Servant
13+import Servant.JS
14+import qualified Servant.JS as SJS
15+import qualified Servant.JS.Angular as NG
16+import System.FilePath
1717
1818-- * A simple Counter data type
1919newtype Counter = Counter { value :: Int }
@@ -43,7 +43,7 @@ type TestApi = "counter" :> Post '[JSON] Counter -- endpoint for increasing the
4343 :<|> "counter" :> Get '[JSON] Counter -- endpoint to get the current value
4444
4545type TestApi' = TestApi
46− :<|> Raw -- used for serving static files
46+ :<|> Raw -- used for serving static files
4747
4848-- this proxy only targets the proper endpoints of our API,
4949-- not the static file serving bit
@@ -82,7 +82,7 @@ writeServiceJS fp =
8282 (defCommonGeneratorOptions { SJS.moduleName = "counterApp" })
8383 )
8484 fp
85−
85+
8686main :: IO ()
8787main = do
8888 -- write the JS code to www/api.js at startup
servant-js/src/Servant/JS.hs+11−11
@@ -1,7 +1,7 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeOperators #-}
3−{-# LANGUAGE FlexibleContexts #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE FlexibleContexts #-}
43{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE TypeOperators #-}
55-----------------------------------------------------------------------------
66-- |
77-- Module : Servant.JS
@@ -114,13 +114,13 @@ module Servant.JS
114114 , AjaxReq
115115 ) where
116116
117−import Data.Proxy
118−import Servant.API
119−import Servant.JS.Angular
120−import Servant.JS.Axios
121−import Servant.JS.Internal
122−import Servant.JS.JQuery
123−import Servant.JS.Vanilla
117+import Data.Proxy
118+import Servant.API
119+import Servant.JS.Angular
120+import Servant.JS.Axios
121+import Servant.JS.Internal
122+import Servant.JS.JQuery
123+import Servant.JS.Vanilla
124124
125125-- | Generate the data necessary to generate javascript code
126126-- for all the endpoints of an API, as ':<|>'-separated values
@@ -160,6 +160,6 @@ instance (GenerateList start, GenerateList rest) => GenerateList (start :<|> res
160160 generateList (start :<|> rest) = (generateList start) ++ (generateList rest)
161161
162162-- | Generate the necessary data for JS codegen as a list, each 'AjaxReq'
163−-- describing one endpoint from your API type.
163+-- describing one endpoint from your API type.
164164listFromAPI :: (HasJS api, GenerateList (JS api)) => Proxy api -> [AjaxReq]
165165listFromAPI p = generateList (javascript p)
servant-js/src/Servant/JS/Angular.hs+13−13
@@ -1,16 +1,16 @@
11module Servant.JS.Angular where
22
3−import Servant.JS.Internal
4−import Control.Lens
5−import Data.List
6−import Data.Monoid
3+import Control.Lens
4+import Data.List
5+import Data.Monoid
6+import Servant.JS.Internal
77
88-- | Options specific to the angular code generator
99data AngularOptions = AngularOptions
1010 { serviceName :: String -- ^ When generating code with wrapInService,
1111 -- name of the service to generate
12− , prologue :: String -> String -> String -- ^ beginning of the service definition
13− , epilogue :: String -- ^ end of the service definition
12+ , prologue :: String -> String -> String -- ^ beginning of the service definition
13+ , epilogue :: String -- ^ end of the service definition
1414 }
1515
1616-- | Default options for the Angular codegen. Used by 'wrapInService'.
@@ -31,7 +31,7 @@ angularService ngOpts = angularServiceWith ngOpts defCommonGeneratorOptions
3131-- | Instead of simply generating top level functions, generates a service instance
3232-- on which your controllers can depend to access your API
3333angularServiceWith :: AngularOptions -> CommonGeneratorOptions -> JavaScriptGenerator
34−angularServiceWith ngOpts opts reqs =
34+angularServiceWith ngOpts opts reqs =
3535 prologue ngOpts svc mName
3636 <> intercalate "," (map generator reqs) <>
3737 epilogue ngOpts
@@ -54,7 +54,7 @@ angularWith ngopts opts = intercalate "\n\n" . map (generateAngularJSWith ngopts
5454-- | js codegen using $http service from Angular using default options
5555generateAngularJS :: AngularOptions -> AjaxReq -> String
5656generateAngularJS ngOpts = generateAngularJSWith ngOpts defCommonGeneratorOptions
57−
57+
5858-- | js codegen using $http service from Angular
5959generateAngularJSWith :: AngularOptions -> CommonGeneratorOptions -> AjaxReq -> String
6060generateAngularJSWith ngOptions opts req = "\n" <>
@@ -74,7 +74,7 @@ generateAngularJSWith ngOptions opts req = "\n" <>
7474 ++ map (view argName) queryparams
7575 ++ body
7676 ++ map (toValidFunctionName . (<>) "header" . headerArgName) hs
77−
77+
7878 -- If we want to generate Top Level Function, they must depend on
7979 -- the $http service, if we generate a service, the functions will
8080 -- inherit this dependency from the service
@@ -118,13 +118,13 @@ generateAngularJSWith ngOptions opts req = "\n" <>
118118 else (moduleName opts) <> "."
119119 where
120120 hasNoModule = null (moduleName opts)
121−
121+
122122 hasService = not $ null (serviceName ngOptions)
123−
123+
124124 fsep = if hasService then ":" else " ="
125−
125+
126126 fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
127−
127+
128128 method = req ^. reqMethod
129129 url = if url' == "'" then "'/'" else url'
130130 url' = "'"
servant-js/src/Servant/JS/Axios.hs+12−12
@@ -1,10 +1,10 @@
11module Servant.JS.Axios where
22
3−import Servant.JS.Internal
4−import Control.Lens
5−import Data.Char (toLower)
6−import Data.List
7−import Data.Monoid
3+import Control.Lens
4+import Data.Char (toLower)
5+import Data.List
6+import Data.Monoid
7+import Servant.JS.Internal
88
99-- | Axios 'configuration' type
1010-- Let you customize the generation using Axios capabilities
@@ -13,9 +13,9 @@ data AxiosOptions = AxiosOptions
1313 -- should be made using credentials
1414 withCredentials :: !Bool
1515 -- | the name of the cookie to use as a value for xsrf token
16− , xsrfCookieName :: !(Maybe String)
16+ , xsrfCookieName :: !(Maybe String)
1717 -- | the name of the header to use as a value for xsrf token
18− , xsrfHeaderName :: !(Maybe String)
18+ , xsrfHeaderName :: !(Maybe String)
1919 }
2020
2121-- | Default instance of the AxiosOptions
@@ -40,7 +40,7 @@ axiosWith aopts opts = intercalate "\n\n" . map (generateAxiosJSWith aopts opts)
4040-- | js codegen using axios library using default options
4141generateAxiosJS :: AxiosOptions -> AjaxReq -> String
4242generateAxiosJS aopts = generateAxiosJSWith aopts defCommonGeneratorOptions
43−
43+
4444-- | js codegen using axios library
4545generateAxiosJSWith :: AxiosOptions -> CommonGeneratorOptions -> AjaxReq -> String
4646generateAxiosJSWith aopts opts req = "\n" <>
@@ -61,7 +61,7 @@ generateAxiosJSWith aopts opts req = "\n" <>
6161 ++ map (view argName) queryparams
6262 ++ body
6363 ++ map (toValidFunctionName . (<>) "header" . headerArgName) hs
64−
64+
6565 captures = map captureArg
6666 . filter isCapture
6767 $ req ^. reqUrl.path
@@ -85,7 +85,7 @@ generateAxiosJSWith aopts opts req = "\n" <>
8585 then " , withCredentials: true\n"
8686 else ""
8787
88− xsrfCookie =
88+ xsrfCookie =
8989 case xsrfCookieName aopts of
9090 Just name -> " , xsrfCookieName: '" <> name <> "'\n"
9191 Nothing -> ""
@@ -111,9 +111,9 @@ generateAxiosJSWith aopts opts req = "\n" <>
111111 else (moduleName opts) <> "."
112112 where
113113 hasNoModule = null (moduleName opts)
114−
114+
115115 fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
116−
116+
117117 method = map toLower $ req ^. reqMethod
118118 url = if url' == "'" then "'/'" else url'
119119 url' = "'"
servant-js/src/Servant/JS/Internal.hs+6−6
@@ -28,7 +28,7 @@ import Servant.API
2828-- | this structure is used by JavaScriptGenerator implementations to let you
2929-- customize the output
3030data CommonGeneratorOptions = CommonGeneratorOptions
31− {
31+ {
3232 functionNameBuilder :: FunctionName -> String -- ^ function generating function names
3333 , requestBody :: String -- ^ name used when a user want to send the request body (to let you redefine it)
3434 , successCallback :: String -- ^ name of the callback parameter when the request was successful
@@ -63,12 +63,12 @@ defCommonGeneratorOptions = CommonGeneratorOptions
6363-- | Function name builder that simply concat each part together
6464concatCase :: FunctionName -> String
6565concatCase = concat
66−
66+
6767-- | Function name builder using the snake_case convention.
6868-- each part is separated by a single underscore character.
6969snakeCase :: FunctionName -> String
7070snakeCase = intercalate "_"
71−
71+
7272-- | Function name builder using the CamelCase convention.
7373-- each part begins with an upper case character.
7474camelCase :: FunctionName -> String
@@ -78,7 +78,7 @@ camelCase (p:ps) = concat $ p : camelCase' ps
7878 camelCase' (r:rs) = capitalize r : camelCase' rs
7979 capitalize [] = []
8080 capitalize (x:xs) = toUpper x : xs
81−
81+
8282type Arg = String
8383
8484-- A 'JavascriptGenerator' just takes the data found in the API type
@@ -141,8 +141,8 @@ toValidFunctionName (x:xs) = [setFirstChar x] <> filter remainder xs
141141 setFirstChar c = if firstChar c
142142 then c
143143 else '_'
144− firstChar c = (prefixOK c) || (or . map (Set.member c) $ firstLetterOK)
145− remainder c = (prefixOK c) || (or . map (Set.member c) $ remainderOK)
144+ firstChar c = prefixOK c || any (Set.member c) firstLetterOK
145+ remainder c = prefixOK c || any (Set.member c) remainderOK
146146 -- Valid prefixes
147147 prefixOK c = c `elem` ['$','_']
148148 -- Unicode character sets
servant-js/src/Servant/JS/JQuery.hs+8−8
@@ -1,20 +1,20 @@
11module Servant.JS.JQuery where
22
3−import Servant.JS.Internal
4−import Control.Lens
5−import Data.List
6−import Data.Monoid
3+import Control.Lens
4+import Data.List
5+import Data.Monoid
6+import Servant.JS.Internal
77
88-- | Generate javascript functions that use the /jQuery/ library
99-- to make the AJAX calls. Uses 'defCommonGeneratorOptions'
1010-- for the generator options.
1111jquery :: JavaScriptGenerator
12−jquery = concat . map generateJQueryJS
12+jquery = concatMap generateJQueryJS
1313
1414-- | Generate javascript functions that use the /jQuery/ library
1515-- to make the AJAX calls. Lets you specify your own 'CommonGeneratorOptions'.
1616jqueryWith :: CommonGeneratorOptions -> JavaScriptGenerator
17−jqueryWith opts = concat . map (generateJQueryJSWith opts)
17+jqueryWith opts = concatMap (generateJQueryJSWith opts)
1818
1919-- | js codegen using JQuery using default options
2020generateJQueryJS :: AjaxReq -> String
@@ -53,7 +53,7 @@ generateJQueryJSWith opts req = "\n" <>
5353 body = if req ^. reqBody
5454 then [requestBody opts]
5555 else []
56−
56+
5757 onSuccess = successCallback opts
5858 onError = errorCallback opts
5959
@@ -77,7 +77,7 @@ generateJQueryJSWith opts req = "\n" <>
7777 then "var "
7878 else (moduleName opts) <> "."
7979 fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
80−
80+
8181 method = req ^. reqMethod
8282 url = if url' == "'" then "'/'" else url'
8383 url' = "'"
servant-js/src/Servant/JS/Vanilla.hs+10−10
@@ -1,21 +1,21 @@
11module Servant.JS.Vanilla where
22
3−import Servant.JS.Internal
4−import Control.Lens
5−import Data.List
6−import Data.Monoid
3+import Control.Lens
4+import Data.List
5+import Data.Monoid
6+import Servant.JS.Internal
77
88-- | Generate vanilla javascript functions to make AJAX requests
99-- to your API, using /XMLHttpRequest/. Uses 'defCommonGeneratorOptions'
1010-- for the 'CommonGeneratorOptions'.
1111vanillaJS :: JavaScriptGenerator
12−vanillaJS = concat . map generateVanillaJS
12+vanillaJS = concatMap generateVanillaJS
1313
1414-- | Generate vanilla javascript functions to make AJAX requests
1515-- to your API, using /XMLHttpRequest/. Lets you specify your
1616-- own options.
1717vanillaJSWith :: CommonGeneratorOptions -> JavaScriptGenerator
18−vanillaJSWith opts = concat . map (generateVanillaJSWith opts)
18+vanillaJSWith opts = concatMap (generateVanillaJSWith opts)
1919
2020-- | js codegen using XmlHttpRequest using default generation options
2121generateVanillaJS :: AjaxReq -> String
@@ -56,11 +56,11 @@ generateVanillaJSWith opts req = "\n" <>
5656 hs = req ^. reqHeaders
5757
5858 queryparams = req ^.. reqUrl.queryStr.traverse
59−
59+
6060 body = if req ^. reqBody
6161 then [requestBody opts]
6262 else []
63−
63+
6464 onSuccess = successCallback opts
6565 onError = errorCallback opts
6666
@@ -68,7 +68,7 @@ generateVanillaJSWith opts req = "\n" <>
6868 if req ^. reqBody
6969 then "JSON.stringify(body)\n"
7070 else "null"
71−
71+
7272
7373 reqheaders =
7474 if null hs
@@ -84,7 +84,7 @@ generateVanillaJSWith opts req = "\n" <>
8484 then "var "
8585 else (moduleName opts) <> "."
8686 fname = namespace <> (functionNameBuilder opts $ req ^. funcName)
87−
87+
8888 method = req ^. reqMethod
8989 url = if url' == "'" then "'/'" else url'
9090 url' = "'"
servant-js/test/Servant/JSSpec.hs+22−22
@@ -7,18 +7,18 @@
77{-# OPTIONS_GHC -fno-warn-orphans #-}
88module Servant.JSSpec where
99
10−import Data.Either (isRight)
11−import Data.Proxy
12−import Language.ECMAScript3.Parser (parseFromString)
13−import Test.Hspec
14−
15−import Servant.API
16−import Servant.JS
17−import qualified Servant.JS.Vanilla as JS
18−import qualified Servant.JS.JQuery as JQ
19−import qualified Servant.JS.Angular as NG
20−import qualified Servant.JS.Axios as AX
21−import Servant.JSSpec.CustomHeaders
10+import Data.Either (isRight)
11+import Data.Proxy
12+import Language.ECMAScript3.Parser (parseFromString)
13+import Test.Hspec
14+
15+import Servant.API
16+import Servant.JS
17+import qualified Servant.JS.Angular as NG
18+import qualified Servant.JS.Axios as AX
19+import qualified Servant.JS.JQuery as JQ
20+import qualified Servant.JS.Vanilla as JS
21+import Servant.JSSpec.CustomHeaders
2222
2323type TestAPI = "simple" :> ReqBody '[JSON,FormUrlEncoded] String :> Post '[JSON] Bool
2424 :<|> "has.extension" :> Get '[FormUrlEncoded,JSON] Bool
@@ -65,7 +65,7 @@ customOptions = defCommonGeneratorOptions
6565 { successCallback = "okCallback"
6666 , errorCallback = "errorCallback"
6767 }
68−
68+
6969spec :: Spec
7070spec = describe "Servant.JQuery" $ do
7171 generateJSSpec Vanilla JS.generateVanillaJS
@@ -76,12 +76,12 @@ spec = describe "Servant.JQuery" $ do
7676 generateJSSpec AngularCustom (NG.generateAngularJSWith NG.defAngularOptions customOptions)
7777 generateJSSpec Axios (AX.generateAxiosJS AX.defAxiosOptions)
7878 generateJSSpec AxiosCustom (AX.generateAxiosJSWith (AX.defAxiosOptions { withCredentials = True }) customOptions)
79−
79+
8080 angularSpec Angular
8181 axiosSpec
8282 --angularSpec AngularCustom
8383
84−axiosSpec :: Spec
84+axiosSpec :: Spec
8585axiosSpec = describe specLabel $ do
8686 it "should add withCredentials when needed" $ do
8787 let jsText = genJS withCredOpts $ listFromAPI (Proxy :: Proxy TestAPI)
@@ -102,20 +102,20 @@ axiosSpec = describe specLabel $ do
102102 cookieOpts = AX.defAxiosOptions { AX.xsrfCookieName = Just "MyXSRFcookie" }
103103 headerOpts = AX.defAxiosOptions { AX.xsrfHeaderName = Just "MyXSRFheader" }
104104 genJS :: AxiosOptions -> [AjaxReq] -> String
105− genJS opts req = concat $ map (AX.generateAxiosJS opts) req
105+ genJS opts req = concatMap (AX.generateAxiosJS opts) req
106106
107−angularSpec :: TestNames -> Spec
107+angularSpec :: TestNames -> Spec
108108angularSpec test = describe specLabel $ do
109109 it "should implement a service globally" $ do
110110 let jsText = genJS $ listFromAPI (Proxy :: Proxy TestAPI)
111111 output jsText
112112 jsText `shouldContain` (".service('" ++ testName ++ "'")
113−
113+
114114 it "should depend on $http service globally" $ do
115115 let jsText = genJS $ listFromAPI (Proxy :: Proxy TestAPI)
116116 output jsText
117117 jsText `shouldContain` ("('" ++ testName ++ "', function($http) {")
118−
118+
119119 it "should not depend on $http service in handlers" $ do
120120 let jsText = genJS $ listFromAPI (Proxy :: Proxy TestAPI)
121121 output jsText
@@ -126,11 +126,11 @@ angularSpec test = describe specLabel $ do
126126 testName = "MyService"
127127 ngOpts = NG.defAngularOptions { NG.serviceName = testName }
128128 genJS req = NG.angularService ngOpts req
129−
129+
130130generateJSSpec :: TestNames -> (AjaxReq -> String) -> Spec
131131generateJSSpec n gen = describe specLabel $ do
132132 it "should generate valid javascript" $ do
133− let s = jsForAPI (Proxy :: Proxy TestAPI) (concat . map gen)
133+ let s = jsForAPI (Proxy :: Proxy TestAPI) (concatMap gen)
134134 parseFromString s `shouldSatisfy` isRight
135135
136136 it "should use non-empty function names" $ do
@@ -167,7 +167,7 @@ generateJSSpec n gen = describe specLabel $ do
167167 jsText `shouldContain` (header n "X-WhatsForDinner" $ "\"I would like \" + headerXWhatsForDinner + \" with a cherry on top.\"")
168168
169169 it "can generate the whole javascript code string at once with jsForAPI" $ do
170− let jsStr = jsForAPI (Proxy :: Proxy TestAPI) (concat . map gen)
170+ let jsStr = jsForAPI (Proxy :: Proxy TestAPI) (concatMap gen)
171171 parseFromString jsStr `shouldSatisfy` isRight
172172 where
173173 specLabel = "generateJS(" ++ (show n) ++ ")"
servant-js/test/Servant/JSSpec/CustomHeaders.hs+7−7
@@ -8,13 +8,13 @@
88
99module Servant.JSSpec.CustomHeaders where
1010
11−import Control.Lens
12−import Data.Monoid
13−import Data.Proxy
14−import GHC.TypeLits
15−import Servant.API
16−import Servant.JS
17−import Servant.JS.Internal
11+import Control.Lens
12+import Data.Monoid
13+import Data.Proxy
14+import GHC.TypeLits
15+import Servant.API
16+import Servant.JS
17+import Servant.JS.Internal
1818
1919-- | This is a hypothetical combinator that fetches an Authorization header.
2020-- The symbol in the header denotes what kind of authentication we are
servant-lucid/Setup.hs+1−1
@@ -1,2 +1,2 @@
1−import Distribution.Simple
1+import Distribution.Simple
22main = defaultMain
servant-mock/Setup.hs+1−1
@@ -1,2 +1,2 @@
1−import Distribution.Simple
1+import Distribution.Simple
22main = defaultMain
servant-mock/example/main.hs+9−9
@@ -1,13 +1,13 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeOperators #-}
3−{-# LANGUAGE DeriveGeneric #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveGeneric #-}
43{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5−import Data.Aeson
6−import GHC.Generics
7−import Network.Wai.Handler.Warp
8−import Servant
9−import Servant.Mock
10−import Test.QuickCheck.Arbitrary
4+{-# LANGUAGE TypeOperators #-}
5+import Data.Aeson
6+import GHC.Generics
7+import Network.Wai.Handler.Warp
8+import Servant
9+import Servant.Mock
10+import Test.QuickCheck.Arbitrary
1111
1212newtype User = User { username :: String }
1313 deriving (Eq, Show, Arbitrary, Generic)
servant-mock/src/Servant/Mock.hs+18−18
@@ -1,10 +1,10 @@
1−{-# LANGUAGE CPP #-}
2−{-# LANGUAGE DataKinds #-}
3−{-# LANGUAGE TypeFamilies #-}
4−{-# LANGUAGE TypeOperators #-}
5−{-# LANGUAGE FlexibleContexts #-}
6−{-# LANGUAGE FlexibleInstances #-}
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DataKinds #-}
3+{-# LANGUAGE FlexibleContexts #-}
4+{-# LANGUAGE FlexibleInstances #-}
75{-# LANGUAGE ScopedTypeVariables #-}
6+{-# LANGUAGE TypeFamilies #-}
7+{-# LANGUAGE TypeOperators #-}
88-- |
99-- Module : Servant.Mock
1010-- Copyright : 2015 Alp Mestanogullari
@@ -51,18 +51,18 @@
5151module Servant.Mock ( HasMock(..) ) where
5252
5353#if !MIN_VERSION_base(4,8,0)
54−import Control.Applicative
54+import Control.Applicative
5555#endif
56−import Control.Monad.IO.Class
57−import Data.ByteString.Lazy.Char8 (pack)
58−import Data.Proxy
59−import GHC.TypeLits
60−import Network.HTTP.Types.Status
61−import Network.Wai
62−import Servant
63−import Servant.API.ContentTypes
64−import Test.QuickCheck.Arbitrary (Arbitrary(..), vector)
65−import Test.QuickCheck.Gen (Gen, generate)
56+import Control.Monad.IO.Class
57+import Data.ByteString.Lazy.Char8 (pack)
58+import Data.Proxy
59+import GHC.TypeLits
60+import Network.HTTP.Types.Status
61+import Network.Wai
62+import Servant
63+import Servant.API.ContentTypes
64+import Test.QuickCheck.Arbitrary (Arbitrary (..), vector)
65+import Test.QuickCheck.Gen (Gen, generate)
6666
6767-- | 'HasMock' defines an interpretation of API types
6868-- than turns them into random-response-generating
@@ -169,7 +169,7 @@ instance HasMock Raw where
169169 bdy <- genBody
170170 respond $ responseLBS status200 [] bdy
171171
172− where genBody = fmap pack $ generate (vector 100 :: Gen [Char])
172+ where genBody = pack <$> generate (vector 100 :: Gen [Char])
173173
174174mockArbitrary :: (MonadIO m, Arbitrary a) => m a
175175mockArbitrary = liftIO (generate arbitrary)
servant-server/Setup.hs+1−1
@@ -1,2 +1,2 @@
1−import Distribution.Simple
1+import Distribution.Simple
22main = defaultMain
servant-server/example/greet.hs+15−15
@@ -1,19 +1,19 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE PolyKinds #-}
3−{-# LANGUAGE TypeFamilies #-}
4−{-# LANGUAGE DeriveGeneric #-}
5−{-# LANGUAGE TypeOperators #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveGeneric #-}
63{-# LANGUAGE OverloadedStrings #-}
7−
8−import Data.Aeson
9−import Data.Monoid
10−import Data.Proxy
11−import Data.Text
12−import GHC.Generics
13−import Network.Wai
14−import Network.Wai.Handler.Warp
15−
16−import Servant
4+{-# LANGUAGE PolyKinds #-}
5+{-# LANGUAGE TypeFamilies #-}
6+{-# LANGUAGE TypeOperators #-}
7+
8+import Data.Aeson
9+import Data.Monoid
10+import Data.Proxy
11+import Data.Text
12+import GHC.Generics
13+import Network.Wai
14+import Network.Wai.Handler.Warp
15+
16+import Servant
1717
1818-- * Example
1919
servant-server/src/Servant.hs+6−6
@@ -14,9 +14,9 @@ module Servant (
1414 Proxy(..),
1515 ) where
1616
17−import Data.Proxy
18−import Servant.API
19−import Servant.Common.Text
20−import Servant.Server
21−import Servant.Utils.Links
22−import Servant.Utils.StaticFiles
17+import Data.Proxy
18+import Servant.API
19+import Servant.Common.Text
20+import Servant.Server
21+import Servant.Utils.Links
22+import Servant.Utils.StaticFiles
servant-server/src/Servant/Server.hs+2−2
@@ -77,8 +77,8 @@ module Servant.Server
7777
7878 ) where
7979
80−import Data.Proxy (Proxy)
81−import Network.Wai (Application)
80+import Data.Proxy (Proxy)
81+import Network.Wai (Application)
8282import Servant.Server.Internal
8383import Servant.Server.Internal.Enter
8484
servant-server/src/Servant/Server/Internal.hs+4−6
@@ -27,7 +27,7 @@ import Control.Monad.Trans.Either (EitherT)
2727import qualified Data.ByteString as B
2828import qualified Data.ByteString.Lazy as BL
2929import qualified Data.Map as M
30−import Data.Maybe (catMaybes, fromMaybe)
30+import Data.Maybe (mapMaybe, fromMaybe)
3131import Data.String (fromString)
3232import Data.String.Conversions (cs, (<>), ConvertibleStrings)
3333import Data.Text (Text)
@@ -137,9 +137,7 @@ processMethodRouter handleA status method headers request = case handleA of
137137 Nothing -> failWith UnsupportedMediaType
138138 Just (contentT, body) -> succeedWith $ responseLBS status hdrs bdy
139139 where
140− bdy = case allowedMethodHead method request of
141− True -> ""
142− False -> body
140+ bdy = if allowedMethodHead method request then "" else body
143141 hdrs = (hContentType, cs contentT) : (fromMaybe [] headers)
144142
145143methodRouter :: (AllCTRender ctypes a)
@@ -512,7 +510,7 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
512510 -- named "foo" or "foo[]" and call fromText on the
513511 -- corresponding values
514512 parameters = filter looksLikeParam querytext
515− values = catMaybes $ map (convert . snd) parameters
513+ values = mapMaybe (convert . snd) parameters
516514 in route (Proxy :: Proxy sublayout) (feedTo subserver values)
517515 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
518516 looksLikeParam (name, _) = name == paramname || name == (paramname <> "[]")
@@ -625,7 +623,7 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
625623 -- named "foo" or "foo[]" and call fromText on the
626624 -- corresponding values
627625 parameters = filter looksLikeParam matrixtext
628− values = catMaybes $ map (convert . snd) parameters
626+ values = mapMaybe (convert . snd) parameters
629627 route (Proxy :: Proxy sublayout) (feedTo subserver values)
630628 _ -> route (Proxy :: Proxy sublayout) (feedTo subserver [])
631629 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
servant-server/src/Servant/Server/Internal/PathInfo.hs+5−5
@@ -1,10 +1,10 @@
1−{-# LANGUAGE OverloadedStrings #-}
1+{-# LANGUAGE OverloadedStrings #-}
22module Servant.Server.Internal.PathInfo where
33
4−import Data.List (unfoldr)
5−import Data.Text (Text)
6−import qualified Data.Text as T
7−import Network.Wai (Request, pathInfo)
4+import Data.List (unfoldr)
5+import Data.Text (Text)
6+import qualified Data.Text as T
7+import Network.Wai (Request, pathInfo)
88
99-- | Like `null . pathInfo`, but works with redundant trailing slashes.
1010pathIsEmpty :: Request -> Bool
servant-server/src/Servant/Server/Internal/Router.hs+5−5
@@ -1,10 +1,10 @@
11module Servant.Server.Internal.Router where
22
3−import Data.Map (Map)
4−import qualified Data.Map as M
5−import Data.Monoid ((<>))
6−import Data.Text (Text)
7−import Network.Wai (Request, pathInfo)
3+import Data.Map (Map)
4+import qualified Data.Map as M
5+import Data.Monoid ((<>))
6+import Data.Text (Text)
7+import Network.Wai (Request, pathInfo)
88import Servant.Server.Internal.PathInfo
99import Servant.Server.Internal.RoutingApplication
1010
servant-server/src/Servant/Server/Internal/RoutingApplication.hs+17−16
@@ -5,23 +5,24 @@
55module Servant.Server.Internal.RoutingApplication where
66
77#if !MIN_VERSION_base(4,8,0)
8−import Control.Applicative (Applicative, (<$>))
9−import Data.Monoid (Monoid, mappend, mempty)
8+import Control.Applicative (Applicative, (<$>))
9+import Data.Monoid (Monoid, mappend, mempty)
1010#endif
11−import Control.Monad.Trans.Either (EitherT, runEitherT)
12−import qualified Data.ByteString as B
13−import qualified Data.ByteString.Lazy as BL
14−import Data.IORef (newIORef, readIORef, writeIORef)
15−import Data.Maybe (fromMaybe)
16−import Data.Monoid ((<>))
17−import Data.String (fromString)
18−import Network.HTTP.Types hiding (Header, ResponseHeaders)
19−import Network.Wai (Application, Request, Response,
20− ResponseReceived,
21− requestBody,
22− responseLBS,
23− strictRequestBody)
24−import Servant.API ((:<|>) (..))
11+import Control.Monad.Trans.Either (EitherT, runEitherT)
12+import qualified Data.ByteString as B
13+import qualified Data.ByteString.Lazy as BL
14+import Data.IORef (newIORef, readIORef,
15+ writeIORef)
16+import Data.Maybe (fromMaybe)
17+import Data.Monoid ((<>))
18+import Data.String (fromString)
19+import Network.HTTP.Types hiding (Header,
20+ ResponseHeaders)
21+import Network.Wai (Application, Request,
22+ Response, ResponseReceived,
23+ requestBody, responseLBS,
24+ strictRequestBody)
25+import Servant.API ((:<|>) (..))
2526import Servant.Server.Internal.ServantErr
2627
2728type RoutingApplication =
servant-server/src/Servant/Server/Internal/ServantErr.hs+4−4
@@ -2,10 +2,10 @@
22{-# LANGUAGE RecordWildCards #-}
33module Servant.Server.Internal.ServantErr where
44
5−import qualified Data.ByteString.Char8 as BS
6−import qualified Data.ByteString.Lazy as LBS
7−import qualified Network.HTTP.Types as HTTP
8−import Network.Wai (responseLBS, Response)
5+import qualified Data.ByteString.Char8 as BS
6+import qualified Data.ByteString.Lazy as LBS
7+import qualified Network.HTTP.Types as HTTP
8+import Network.Wai (Response, responseLBS)
99
1010data ServantErr = ServantErr { errHTTPCode :: Int
1111 , errReasonPhrase :: String
servant-server/src/Servant/Utils/StaticFiles.hs+6−5
@@ -7,12 +7,13 @@ module Servant.Utils.StaticFiles (
77 serveDirectory,
88 ) where
99
10−import System.FilePath (addTrailingPathSeparator)
11−import Network.Wai.Application.Static (staticApp, defaultFileServerSettings)
12−import Servant.API.Raw (Raw)
13−import Servant.Server (Server)
10+import Network.Wai.Application.Static (defaultFileServerSettings,
11+ staticApp)
12+import Servant.API.Raw (Raw)
13+import Servant.Server (Server)
14+import System.FilePath (addTrailingPathSeparator)
1415#if !MIN_VERSION_wai_app_static(3,1,0)
15−import Filesystem.Path.CurrentOS (decodeString)
16+import Filesystem.Path.CurrentOS (decodeString)
1617#endif
1718
1819-- | Serve anything under the specified directory as a 'Raw' endpoint.
servant-server/test/Doctests.hs+1−1
@@ -1,6 +1,6 @@
11module Main where
22
3−import Data.List (isPrefixOf)
3+import Data.List (isPrefixOf)
44import System.Directory
55import System.FilePath
66import System.FilePath.Find
servant-server/test/Servant/Server/Internal/EnterSpec.hs+4−4
@@ -3,16 +3,16 @@
33{-# LANGUAGE TypeOperators #-}
44module Servant.Server.Internal.EnterSpec where
55
6−import qualified Control.Category as C
6+import qualified Control.Category as C
77import Control.Monad.Reader
88import Control.Monad.Trans.Either
99import Data.Proxy
1010import Servant.API
1111import Servant.Server
1212
13−import Test.Hspec (Spec, describe, it)
14−import Test.Hspec.Wai (get, matchStatus, post,
15− shouldRespondWith, with)
13+import Test.Hspec (Spec, describe, it)
14+import Test.Hspec.Wai (get, matchStatus, post,
15+ shouldRespondWith, with)
1616
1717spec :: Spec
1818spec = describe "module Servant.Server.Enter" $ do
servant-server/test/Servant/Utils/StaticFilesSpec.hs+20−18
@@ -1,27 +1,29 @@
1−{-# LANGUAGE DataKinds #-}
1+{-# LANGUAGE DataKinds #-}
22{-# LANGUAGE FlexibleInstances #-}
33{-# LANGUAGE OverloadedStrings #-}
4−{-# LANGUAGE TypeOperators #-}
4+{-# LANGUAGE TypeOperators #-}
55{-# OPTIONS_GHC -fno-warn-orphans #-}
66module Servant.Utils.StaticFilesSpec where
77
8−import Control.Exception (bracket)
9−import Data.Proxy (Proxy(Proxy))
10−import Network.Wai (Application)
11−import System.Directory (getCurrentDirectory, setCurrentDirectory, createDirectory)
12−import System.IO.Temp (withSystemTempDirectory)
13−import Test.Hspec (Spec, describe, it, around_)
14−import Test.Hspec.Wai (with, get, shouldRespondWith)
8+import Control.Exception (bracket)
9+import Data.Proxy (Proxy (Proxy))
10+import Network.Wai (Application)
11+import System.Directory (createDirectory,
12+ getCurrentDirectory,
13+ setCurrentDirectory)
14+import System.IO.Temp (withSystemTempDirectory)
15+import Test.Hspec (Spec, around_, describe, it)
16+import Test.Hspec.Wai (get, shouldRespondWith, with)
1517
16−import Servant.API (JSON)
17−import Servant.API.Alternative ((:<|>)((:<|>)))
18−import Servant.API.Capture (Capture)
19−import Servant.API.Get (Get)
20−import Servant.API.Raw (Raw)
21−import Servant.API.Sub ((:>))
22−import Servant.Server (Server, serve)
23−import Servant.ServerSpec (Person(Person))
24−import Servant.Utils.StaticFiles (serveDirectory)
18+import Servant.API (JSON)
19+import Servant.API.Alternative ((:<|>) ((:<|>)))
20+import Servant.API.Capture (Capture)
21+import Servant.API.Get (Get)
22+import Servant.API.Raw (Raw)
23+import Servant.API.Sub ((:>))
24+import Servant.Server (Server, serve)
25+import Servant.ServerSpec (Person (Person))
26+import Servant.Utils.StaticFiles (serveDirectory)
2527
2628type Api =
2729 "dummy_api" :> Capture "person_name" String :> Get '[JSON] Person
servant/Setup.hs+1−1
@@ -1,2 +1,2 @@
1−import Distribution.Simple
1+import Distribution.Simple
22main = defaultMain
servant/default.nix−24
@@ -1,24 +0,0 @@
1−{ mkDerivation, aeson, attoparsec, base, bytestring
2−, bytestring-conversion, case-insensitive, directory, doctest
3−, filemanip, filepath, hspec, http-media, http-types, network-uri
4−, parsec, QuickCheck, quickcheck-instances, stdenv
5−, string-conversions, text, url, vault
6−}:
7−mkDerivation {
8− pname = "servant";
9− version = "0.5";
10− src = ./.;
11− buildDepends = [
12− aeson attoparsec base bytestring bytestring-conversion
13− case-insensitive http-media http-types network-uri
14− string-conversions text vault
15− ];
16− testDepends = [
17− aeson attoparsec base bytestring directory doctest filemanip
18− filepath hspec parsec QuickCheck quickcheck-instances
19− string-conversions text url
20− ];
21− homepage = "http://haskell-servant.github.io/";
22− description = "A family of combinators for defining webservices APIs";
23− license = stdenv.lib.licenses.bsd3;
24−}
servant/src/Servant/API.hs+2−2
@@ -69,8 +69,8 @@ import Servant.API.ContentTypes (Accept (..), FormUrlEncoded,
6969import Servant.API.Delete (Delete)
7070import Servant.API.Get (Get)
7171import Servant.API.Header (Header (..))
72−import Servant.API.HttpVersion (HttpVersion(..))
73−import Servant.API.IsSecure (IsSecure(..))
72+import Servant.API.HttpVersion (HttpVersion (..))
73+import Servant.API.IsSecure (IsSecure (..))
7474import Servant.API.MatrixParam (MatrixFlag, MatrixParam,
7575 MatrixParams)
7676import Servant.API.Patch (Patch)
servant/src/Servant/API/Delete.hs+1−1
@@ -4,7 +4,7 @@
44{-# OPTIONS_HADDOCK not-home #-}
55module Servant.API.Delete (Delete) where
66
7−import Data.Typeable ( Typeable )
7+import Data.Typeable (Typeable)
88
99-- | Combinator for DELETE requests.
1010--
servant/src/Servant/API/HttpVersion.hs+1−1
@@ -3,7 +3,7 @@ module Servant.API.HttpVersion
33 HttpVersion(..)
44 ) where
55
6−import Network.HTTP.Types (HttpVersion(..))
6+import Network.HTTP.Types (HttpVersion (..))
77
88-- $httpversion
99--
servant/src/Servant/API/IsSecure.hs+1−1
@@ -4,7 +4,7 @@ module Servant.API.IsSecure
44 IsSecure(..)
55 ) where
66
7−import Data.Typeable
7+import Data.Typeable
88
99-- | Was this request made over an SSL connection?
1010--
servant/src/Servant/API/Put.hs+1−1
@@ -4,7 +4,7 @@
44{-# OPTIONS_HADDOCK not-home #-}
55module Servant.API.Put (Put) where
66
7−import Data.Typeable ( Typeable )
7+import Data.Typeable (Typeable)
88
99-- | Endpoint for PUT requests, usually used to update a ressource.
1010-- The type @a@ is the type of the response body that's returned.
servant/src/Servant/API/Raw.hs+1−1
@@ -2,7 +2,7 @@
22{-# OPTIONS_HADDOCK not-home #-}
33module Servant.API.Raw where
44
5−import Data.Typeable (Typeable)
5+import Data.Typeable (Typeable)
66-- | Endpoint for plugging in your own Wai 'Application's.
77--
88-- The given 'Application' will get the request as received by the server, potentially with
servant/src/Servant/API/RemoteHost.hs+1−1
@@ -4,7 +4,7 @@ module Servant.API.RemoteHost
44 RemoteHost
55 ) where
66
7−import Data.Typeable
7+import Data.Typeable
88
99-- | Provides access to the host or IP address
1010-- from which the HTTP request was sent.
servant/src/Servant/API/Vault.hs+1−1
@@ -3,7 +3,7 @@ module Servant.API.Vault
33 Vault
44 ) where
55
6−import Data.Vault.Lazy (Vault)
6+import Data.Vault.Lazy (Vault)
77
88-- $vault
99--
servant/test/Doctests.hs+1−1
@@ -1,6 +1,6 @@
11module Main where
22
3−import Data.List (isPrefixOf)
3+import Data.List (isPrefixOf)
44import System.Directory
55import System.FilePath
66import System.FilePath.Find
servant/test/Servant/API/ContentTypesSpec.hs+14−14
@@ -12,22 +12,22 @@ import Data.Monoid
1212#endif
1313import Control.Arrow
1414import Data.Aeson
15+import Data.ByteString.Char8 (ByteString, append, pack)
16+import qualified Data.ByteString.Lazy as BSL
1517import Data.Either
16−import Data.Function (on)
18+import Data.Function (on)
19+import Data.List (maximumBy)
20+import Data.Maybe (fromJust, isJust, isNothing)
1721import Data.Proxy
18−import Data.ByteString.Char8 (ByteString, append, pack)
19−import qualified Data.ByteString.Lazy as BSL
20−import Data.List (maximumBy)
21−import Data.Maybe (fromJust, isJust, isNothing)
22−import Data.String (IsString (..))
23−import Data.String.Conversions (cs)
24−import qualified Data.Text as TextS
25−import qualified Data.Text.Lazy as TextL
22+import Data.String (IsString (..))
23+import Data.String.Conversions (cs)
24+import qualified Data.Text as TextS
25+import qualified Data.Text.Lazy as TextL
2626import GHC.Generics
27−import Network.URL (exportParams, importParams)
27+import Network.URL (exportParams, importParams)
2828import Test.Hspec
2929import Test.QuickCheck
30−import Test.QuickCheck.Instances ()
30+import Test.QuickCheck.Instances ()
3131
3232import Servant.API.ContentTypes
3333
@@ -57,15 +57,15 @@ spec = describe "Servant.API.ContentTypes" $ do
5757 let p = Proxy :: Proxy FormUrlEncoded
5858
5959 it "has mimeUnrender reverse mimeRender" $ do
60− property $ \x -> all (/= mempty) x
60+ property $ \x -> mempty `notElem` x
6161 ==> mimeUnrender p (mimeRender p x) == Right (x::[(TextS.Text,TextS.Text)])
6262
6363 it "has mimeUnrender reverse exportParams (Network.URL)" $ do
64− property $ \x -> all (/= mempty) x
64+ property $ \x -> mempty `notElem` x
6565 ==> (mimeUnrender p . cs . exportParams . map (cs *** cs) $ x) == Right (x::[(TextS.Text,TextS.Text)])
6666
6767 it "has importParams (Network.URL) reverse mimeRender" $ do
68− property $ \x -> all (/= mempty) x
68+ property $ \x -> mempty `notElem` x
6969 ==> (fmap (map (cs *** cs)) . importParams . cs . mimeRender p $ x) == Just (x::[(TextS.Text,TextS.Text)])
7070
7171 describe "The PlainText Content-Type type" $ do