forked from loafle/openapi-generator-original
[Haskell-Servant] Upgrade to Servant 0.16 (#2849)
This commit is contained in:
committed by
William Cheng
parent
757fcfeac6
commit
48314905da
@@ -52,10 +52,10 @@ import Network.HTTP.Client (Manager, newManager)
|
||||
import Network.HTTP.Client.TLS (tlsManagerSettings)
|
||||
import Network.HTTP.Types.Method (methodOptions)
|
||||
import qualified Network.Wai.Handler.Warp as Warp
|
||||
import Servant (ServantErr, serve)
|
||||
import Servant (ServerError, serve)
|
||||
import Servant.API
|
||||
import Servant.API.Verbs (StdMethod (..), Verb)
|
||||
import Servant.Client (ClientEnv, Scheme (Http), ServantError, client,
|
||||
import Servant.Client (ClientEnv, Scheme (Http), ClientError, client,
|
||||
mkClientEnv, parseBaseUrl)
|
||||
import Servant.Client.Core (baseUrlPort, baseUrlHost)
|
||||
import Servant.Client.Internal.HttpClient (ClientM (..))
|
||||
@@ -140,7 +140,7 @@ data Config = Config
|
||||
|
||||
|
||||
-- | Custom exception type for our errors.
|
||||
newtype {{title}}ClientError = {{title}}ClientError ServantError
|
||||
newtype {{title}}ClientError = {{title}}ClientError ClientError
|
||||
deriving (Show, Exception)
|
||||
-- | Configuration, specifying the full url of the service.
|
||||
|
||||
@@ -157,7 +157,7 @@ data {{title}}Backend m = {{title}}Backend
|
||||
}
|
||||
|
||||
newtype {{title}}Client a = {{title}}Client
|
||||
{ runClient :: ClientEnv -> ExceptT ServantError IO a
|
||||
{ runClient :: ClientEnv -> ExceptT ClientError IO a
|
||||
} deriving Functor
|
||||
|
||||
instance Applicative {{title}}Client where
|
||||
@@ -184,13 +184,13 @@ create{{title}}Client = {{title}}Backend{..}
|
||||
{{/hasMore}}{{/apis}}) = client (Proxy :: Proxy {{title}}API)
|
||||
|
||||
-- | Run requests in the {{title}}Client monad.
|
||||
run{{title}}Client :: Config -> {{title}}Client a -> ExceptT ServantError IO a
|
||||
run{{title}}Client :: Config -> {{title}}Client a -> ExceptT ClientError IO a
|
||||
run{{title}}Client clientConfig cl = do
|
||||
manager <- liftIO $ newManager tlsManagerSettings
|
||||
run{{title}}ClientWithManager manager clientConfig cl
|
||||
|
||||
-- | Run requests in the {{title}}Client monad using a custom manager.
|
||||
run{{title}}ClientWithManager :: Manager -> Config -> {{title}}Client a -> ExceptT ServantError IO a
|
||||
run{{title}}ClientWithManager :: Manager -> Config -> {{title}}Client a -> ExceptT ClientError IO a
|
||||
run{{title}}ClientWithManager manager Config{..} cl = do
|
||||
url <- parseBaseUrl configUrl
|
||||
runClient cl $ mkClientEnv manager url
|
||||
@@ -211,7 +211,7 @@ call{{title}} env f = do
|
||||
-- | Run the {{title}} server at the provided host and port.
|
||||
run{{title}}Server
|
||||
:: (MonadIO m, MonadThrow m)
|
||||
=> Config -> {{title}}Backend (ExceptT ServantErr IO) -> m ()
|
||||
=> Config -> {{title}}Backend (ExceptT ServerError IO) -> m ()
|
||||
run{{title}}Server Config{..} backend = do
|
||||
url <- parseBaseUrl configUrl
|
||||
let warpSettings = Warp.defaultSettings
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
resolver: lts-12.18
|
||||
extra-deps: []
|
||||
resolver: lts-13.20
|
||||
extra-deps:
|
||||
- servant-0.16
|
||||
- servant-server-0.16
|
||||
- servant-client-0.16
|
||||
- servant-client-core-0.16
|
||||
packages:
|
||||
- '.'
|
||||
nix:
|
||||
|
||||
@@ -1 +1 @@
|
||||
4.0.0-beta3
|
||||
4.0.0-SNAPSHOT
|
||||
@@ -52,10 +52,10 @@ import Network.HTTP.Client (Manager, newManager)
|
||||
import Network.HTTP.Client.TLS (tlsManagerSettings)
|
||||
import Network.HTTP.Types.Method (methodOptions)
|
||||
import qualified Network.Wai.Handler.Warp as Warp
|
||||
import Servant (ServantErr, serve)
|
||||
import Servant (ServerError, serve)
|
||||
import Servant.API
|
||||
import Servant.API.Verbs (StdMethod (..), Verb)
|
||||
import Servant.Client (ClientEnv, Scheme (Http), ServantError, client,
|
||||
import Servant.Client (ClientEnv, Scheme (Http), ClientError, client,
|
||||
mkClientEnv, parseBaseUrl)
|
||||
import Servant.Client.Core (baseUrlPort, baseUrlHost)
|
||||
import Servant.Client.Internal.HttpClient (ClientM (..))
|
||||
@@ -163,7 +163,7 @@ data Config = Config
|
||||
|
||||
|
||||
-- | Custom exception type for our errors.
|
||||
newtype OpenAPIPetstoreClientError = OpenAPIPetstoreClientError ServantError
|
||||
newtype OpenAPIPetstoreClientError = OpenAPIPetstoreClientError ClientError
|
||||
deriving (Show, Exception)
|
||||
-- | Configuration, specifying the full url of the service.
|
||||
|
||||
@@ -196,7 +196,7 @@ data OpenAPIPetstoreBackend m = OpenAPIPetstoreBackend
|
||||
}
|
||||
|
||||
newtype OpenAPIPetstoreClient a = OpenAPIPetstoreClient
|
||||
{ runClient :: ClientEnv -> ExceptT ServantError IO a
|
||||
{ runClient :: ClientEnv -> ExceptT ClientError IO a
|
||||
} deriving Functor
|
||||
|
||||
instance Applicative OpenAPIPetstoreClient where
|
||||
@@ -238,13 +238,13 @@ createOpenAPIPetstoreClient = OpenAPIPetstoreBackend{..}
|
||||
(coerce -> updateUser)) = client (Proxy :: Proxy OpenAPIPetstoreAPI)
|
||||
|
||||
-- | Run requests in the OpenAPIPetstoreClient monad.
|
||||
runOpenAPIPetstoreClient :: Config -> OpenAPIPetstoreClient a -> ExceptT ServantError IO a
|
||||
runOpenAPIPetstoreClient :: Config -> OpenAPIPetstoreClient a -> ExceptT ClientError IO a
|
||||
runOpenAPIPetstoreClient clientConfig cl = do
|
||||
manager <- liftIO $ newManager tlsManagerSettings
|
||||
runOpenAPIPetstoreClientWithManager manager clientConfig cl
|
||||
|
||||
-- | Run requests in the OpenAPIPetstoreClient monad using a custom manager.
|
||||
runOpenAPIPetstoreClientWithManager :: Manager -> Config -> OpenAPIPetstoreClient a -> ExceptT ServantError IO a
|
||||
runOpenAPIPetstoreClientWithManager :: Manager -> Config -> OpenAPIPetstoreClient a -> ExceptT ClientError IO a
|
||||
runOpenAPIPetstoreClientWithManager manager Config{..} cl = do
|
||||
url <- parseBaseUrl configUrl
|
||||
runClient cl $ mkClientEnv manager url
|
||||
@@ -263,7 +263,7 @@ callOpenAPIPetstore env f = do
|
||||
-- | Run the OpenAPIPetstore server at the provided host and port.
|
||||
runOpenAPIPetstoreServer
|
||||
:: (MonadIO m, MonadThrow m)
|
||||
=> Config -> OpenAPIPetstoreBackend (ExceptT ServantErr IO) -> m ()
|
||||
=> Config -> OpenAPIPetstoreBackend (ExceptT ServerError IO) -> m ()
|
||||
runOpenAPIPetstoreServer Config{..} backend = do
|
||||
url <- parseBaseUrl configUrl
|
||||
let warpSettings = Warp.defaultSettings
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
resolver: lts-12.18
|
||||
extra-deps: []
|
||||
resolver: lts-13.20
|
||||
extra-deps:
|
||||
- servant-0.16
|
||||
- servant-server-0.16
|
||||
- servant-client-0.16
|
||||
- servant-client-core-0.16
|
||||
packages:
|
||||
- '.'
|
||||
nix:
|
||||
|
||||
Reference in New Issue
Block a user