Quantcast

Embed servant-swagger-ui plain Handler into custom ServerT stack

Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Embed servant-swagger-ui plain Handler into custom ServerT stack

Jan-Philip Loos
Hi,

thanks for the servant framework, it's a pleasure to work with it. The most head scratching issues are coming from transforming your monad stack into the servant domain. Now I'm stuck with the reverse case:

Say I have custom servant stack with my monad embedded and the following API with swagger-ui included (from 


import Servant
import Servant.Swagger.UI
import Data.Swagger
import Control.Monad.Reader
import Data.Text
import Data.Proxy

type EndpointM =  ReaderT Env IO

type Service = ServerT API EndpointM

type BaseAPI = "myHandler" :> Get '[PlainText] (Int,Int)
type API = BaseAPI :<|> SwaggerSchemaUI "swagger-ui" "swagger.json"




and now I want to compose two handlers, one with my custom monad stack and the one from Servant.Swagger.UI


 

myService :: ServerT API EndpointM
myService = myHandler :<|> _help (swaggerSchemaUIServer (toSwagger (Proxy::Proxy BaseAPI) & host ?~ "example.com"))

myHandler :: EndpointM (Int,Int)
myHandler = return (42, 53)

My problem here is, I don't now how to embed the swaggerSchemaUIServer in the right way. I could not find a right solution to `_help` hole with this type:

    • Found hole:

        _help

          :: Server (SwaggerSchemaUI' dir0 api0)

             -> ReaderT Env IO Swagger

                :<|> (ReaderT

                        Env

                        IO

                        (SwaggerUiHtml

                           "swagger-ui" ("swagger.json" :> Get '[JSON] Swagger))

                      :<|> (ReaderT

                              Env

                              IO

                              (SwaggerUiHtml

                                 "swagger-ui" ("swagger.json" :> Get '[JSON] Swagger))

                            :<|> Application))

      Where: ‘dir0’ is an ambiguous type variable

             ‘api0’ is an ambiguous type variable


I appreciate any help!

Jan

--
Loading...