servant-util 0.1.0.1 → 0.1.0.2
raw patch · 7 files changed
+66/−15 lines, 7 files
Files
- examples/Books.hs +30/−6
- examples/Main.hs +3/−1
- servant-util.cabal +2/−4
- src/Servant/Util/Combinators.hs +10/−1
- src/Servant/Util/Combinators/Filtering/Filters.hs +6/−1
- src/Servant/Util/Common.hs +7/−1
- src/Servant/Util/Dummy.hs +8/−1
examples/Books.hs view
@@ -1,32 +1,52 @@+{-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE DerivingStrategies #-}+ module Books where import Universum import Data.Aeson (FromJSON, ToJSON) import Data.Aeson.TH (defaultOptions, deriveJSON)+import Data.Swagger (Swagger, ToParamSchema, ToSchema) import Fmt (Buildable (..), (+|), (|+)) import qualified Network.Wai.Handler.Warp as Warp import Servant (FromHttpApiData, Get, JSON, PostCreated, QueryParam, ReqBody, Server, serve, (:<|>) (..), (:>))+import Servant.Swagger (toSwagger)+import Servant.Swagger.UI (SwaggerSchemaUI, swaggerSchemaUIServer) import Servant.Util newtype Isbn = Isbn Word64- deriving (Eq, Show, ToJSON, FromJSON)+ deriving stock (Eq, Show, Generic)+ deriving newtype (ToJSON, FromJSON, ToSchema, ToParamSchema, FromHttpApiData) +type instance SupportedFilters Isbn = '[FilterMatching, FilterComparing]++type instance ParamDescription Isbn = "ISBN of a book"+type instance ParamDescription Text = "Text"+ data Book = Book { isbn :: Isbn , bookName :: Text , author :: Text }+ deriving (Generic)+ deriving anyclass (ToSchema) deriveJSON defaultOptions 'Book newtype Password = Password Text- deriving (FromHttpApiData)+ deriving stock (Generic)+ deriving newtype (FromHttpApiData, ToParamSchema) type GetBooks- = Get '[JSON] [Book]+ = SortingParams+ '["isbn" ?: Isbn, "name" ?: Text, "author" ?: Text]+ '["isbn" ?: 'Asc Isbn]+ :> FilteringParams ["isbn" ?: 'AutoFilter Isbn, "name" ?: 'AutoFilter Text]+ :> PaginationParams ('DefPageSize 20)+ :> Get '[JSON] [Book] type AddBook = QueryParam "password" Password@@ -38,9 +58,12 @@ AddBook ) +swagger :: Swagger+swagger = toSwagger @BooksAPI Proxy+ booksHandlers :: Server BooksAPI booksHandlers =- (return [])+ (\_sorting _filtering _pagination -> return []) :<|> (\_ book -> return (isbn book)) @@ -74,7 +97,8 @@ serveBooksServer :: IO () serveBooksServer = Warp.runSettings warpSettings $- serverWithLogging loggingConfig (Proxy @BooksAPI) $ \sp ->- serve sp booksHandlers+ serverWithLogging loggingConfig (Proxy @BooksAPI) $ \(Proxy :: Proxy api) ->+ serve @(SwaggerSchemaUI "swagger-ui" "swagger.json" :<|> api) Proxy+ (swaggerSchemaUIServer swagger :<|> booksHandlers) where loggingConfig = ServantLogConfig putTextLn
examples/Main.hs view
@@ -2,5 +2,7 @@ import Universum +import Books+ main :: IO ()-main = pass+main = serveBooksServer
servant-util.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: de73541e9d975e3ed0fdec0ca76af4a65ee45c1ba3e85c9dde8b9b02b103cac4+-- hash: 162d0c665afc7e688062cc1007aa9fbc6aa2a300ac096144fffd1cd576b6fee1 name: servant-util-version: 0.1.0.1+version: 0.1.0.2 synopsis: Servant servers utilities. description: Basement for common Servant combinators like filtering, sorting, pagination and semantical logging. category: Servant, Web@@ -75,8 +75,6 @@ src default-extensions: AllowAmbiguousTypes BangPatterns ConstraintKinds DataKinds DefaultSignatures DeriveDataTypeable DeriveGeneric EmptyCase FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving LambdaCase MultiParamTypeClasses MultiWayIf NamedFieldPuns NoImplicitPrelude OverloadedStrings OverloadedLabels PatternSynonyms RankNTypes RecordWildCards ScopedTypeVariables StandaloneDeriving TemplateHaskell TupleSections TypeFamilies TypeOperators UndecidableInstances ViewPatterns TypeApplications ghc-options: -Wall- build-tool-depends:- autoexporter:autoexporter build-depends: QuickCheck , aeson
src/Servant/Util/Combinators.hs view
@@ -1,1 +1,10 @@-{-# OPTIONS_GHC -F -pgmF autoexporter -Wno-dodgy-exports -Wno-unused-imports #-}+module Servant.Util.Combinators+ ( module M+ ) where++import Servant.Util.Combinators.ErrorResponses as M+import Servant.Util.Combinators.Filtering as M+import Servant.Util.Combinators.Logging as M+import Servant.Util.Combinators.Pagination as M+import Servant.Util.Combinators.Sorting as M+import Servant.Util.Combinators.Tag as M
src/Servant/Util/Combinators/Filtering/Filters.hs view
@@ -1,2 +1,7 @@ -- | Various filter types.-{-# OPTIONS_GHC -F -pgmF autoexporter -Wno-dodgy-exports -Wno-unused-imports #-}+module Servant.Util.Combinators.Filtering.Filters+ ( module M+ ) where++import Servant.Util.Combinators.Filtering.Filters.General as M+import Servant.Util.Combinators.Filtering.Filters.Like as M
src/Servant/Util/Common.hs view
@@ -1,1 +1,7 @@-{-# OPTIONS_GHC -F -pgmF autoexporter -Wno-dodgy-exports -Wno-unused-imports #-}+module Servant.Util.Common+ ( module M+ ) where++import Servant.Util.Common.Common as M+import Servant.Util.Common.HList as M+import Servant.Util.Common.PolyKinds as M
src/Servant/Util/Dummy.hs view
@@ -1,2 +1,9 @@ -- | Contains dummy backend implementations for introduced combinators.-{-# OPTIONS_GHC -F -pgmF autoexporter -Wno-dodgy-exports -Wno-unused-imports #-}++module Servant.Util.Dummy+ ( module M+ ) where++import Servant.Util.Dummy.Filtering as M+import Servant.Util.Dummy.Pagination as M+import Servant.Util.Dummy.Sorting as M