forked from loafle/openapi-generator-original
[haskell][server] Export the Wai Application for the server (#9801)
For tests it’s useful to have direct access to the Wai `Application`, which is the plain function from `Request` to `Response`. Then you don’t need to use a full-blown http server to run requests.
This commit is contained in:
@@ -27,6 +27,8 @@ module {{title}}.API
|
||||
, {{title}}ClientError(..)
|
||||
-- ** Servant
|
||||
, {{title}}API
|
||||
-- ** Plain WAI Application
|
||||
, serverWaiApplication{{title}}
|
||||
) where
|
||||
|
||||
import {{title}}.Types
|
||||
@@ -232,7 +234,13 @@ run{{title}}MiddlewareServer Config{..} middleware backend = do
|
||||
let warpSettings = Warp.defaultSettings
|
||||
& Warp.setPort (baseUrlPort url)
|
||||
& Warp.setHost (fromString $ baseUrlHost url)
|
||||
liftIO $ Warp.runSettings warpSettings $ middleware $ serve (Proxy :: Proxy {{title}}API) (serverFromBackend backend)
|
||||
liftIO $ Warp.runSettings warpSettings $ middleware $ serverWaiApplication{{title}} backend
|
||||
|
||||
-- | Plain "Network.Wai" Application for the {{title}} server.
|
||||
--
|
||||
-- Can be used to implement e.g. tests that call the API without a full webserver.
|
||||
serverWaiApplication{{title}} :: {{title}}Backend (ExceptT ServerError IO) -> Application
|
||||
serverWaiApplication{{title}} backend = serve (Proxy :: Proxy {{title}}API) (serverFromBackend backend)
|
||||
where
|
||||
serverFromBackend {{title}}Backend{..} =
|
||||
({{#apis}}{{#operations}}{{#operation}}coerce {{operationId}}{{^-last}} :<|>
|
||||
|
||||
Reference in New Issue
Block a user