| Copyright | (C) 2016 Oleg Grenrus |
|---|---|
| License | BSD3 |
| Maintainer | Oleg Grenrus <oleg.grenrus@iki.fi> |
| Safe Haskell | None |
| Language | Haskell2010 |
Servant.Swagger.UI
Contents
Description
Provides SwaggerUI and corresponding swaggerUIServer to embed
swagger ui into the application.
All of UI files are embedded into the binary.
An example:
-- | Actual API
type BasicAPI = Get '[PlainText, JSON] Text
:<|> "cat" :> Capture ":name" CatName :> Get '[JSON] Cat
-- | Swagger schema endpoint
type SwaggerSchemaEndpoint = "swagger.js" :> Get '[JSON] Swagger
-- | Unhabitated new data type, to be able to refer to API type from the API type.
data API
-- | Underlying API type
type API' = BasicAPI
:<|> SwaggerSchemaEndpoint
:<|> SwaggerUI "ui" SwaggerSchemaEndpoint API
-- Unfortunately we have to write those trivial instances.
-- Optionally we can do:
-- data API'= BasicAPI
-- :<|> SwaggerSchemaEndpoint
--
-- | Underlying API type
-- type API = API'
-- :<|> SwaggerUI "ui" SwaggerSchemaEndpoint API'
instance HasServer API where
type ServerT API m = ServerT API' m
route _ = route (Proxy :: Proxy API')
type instance IsElem' e API = IsElem e API'
server :: Server API
server =
(pure "Hello World" :<|> catEndpoint)
:<|> pure swaggerDoc
:<|> swaggerUIServer
where
catEndpoint name = pure $ Cat name False
- type SwaggerUI dir endpoint api = dir :> (Get '[HTML] (SwaggerUiHtml endpoint api) :<|> (("index.html" :> Get '[HTML] (SwaggerUiHtml endpoint api)) :<|> Raw))
- swaggerUIServer :: Server (SwaggerUI dir endpoint api)
- data SwaggerUiHtml endpoint api = SwaggerUiHtml
Swagger UI API
type SwaggerUI dir endpoint api = dir :> (Get '[HTML] (SwaggerUiHtml endpoint api) :<|> (("index.html" :> Get '[HTML] (SwaggerUiHtml endpoint api)) :<|> Raw)) Source #
Swagger API ui.
swaggerUIServer :: Server (SwaggerUI dir endpoint api) Source #
Internals
data SwaggerUiHtml endpoint api Source #
Index file for swagger ui.
It's configured by the location of swagger schema.
Constructors
| SwaggerUiHtml |