Copyright | (C) 2016 Oleg Grenrus |
---|---|
License | BSD3 |
Maintainer | Oleg Grenrus <oleg.grenrus@iki.fi> |
Safe Haskell | None |
Language | Haskell2010 |
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 -- | API type with bells and whistles, i.e. schema file and swagger-ui. type API =SwaggerSchemaUI
"swagger-ui" "swagger.json" :<|> BasicAPI -- | Servant server for an API server :: Server API server =swaggerSchemaUIServer
swaggerDoc :<|> (pure "Hello World" :<|> catEndpoint) where catEndpoint name = pure $ Cat name False
- type SwaggerSchemaUI dir schema = SwaggerSchemaUI' dir (schema :> Get '[JSON] Swagger)
- type SwaggerSchemaUI' dir api = api :<|> (dir :> (Get '[HTML] (SwaggerUiHtml dir api) :<|> (("index.html" :> Get '[HTML] (SwaggerUiHtml dir api)) :<|> Raw)))
- swaggerSchemaUIServer :: Server api ~ Handler Swagger => Swagger -> Server (SwaggerSchemaUI' dir api)
- jensolegSwaggerSchemaUIServer :: Server api ~ Handler Swagger => Swagger -> Server (SwaggerSchemaUI' dir api)
- data SwaggerUiHtml dir api = SwaggerUiHtml Text
- swaggerSchemaUIServerImpl :: Server api ~ Handler Swagger => Text -> [(FilePath, ByteString)] -> Swagger -> Server (SwaggerSchemaUI' dir api)
- swaggerUiIndexTemplate :: Text
- swaggerUiFiles :: [(FilePath, ByteString)]
- jensolegIndexTemplate :: Text
- jensolegFiles :: [(FilePath, ByteString)]
Swagger UI API
type SwaggerSchemaUI dir schema = SwaggerSchemaUI' dir (schema :> Get '[JSON] Swagger) Source #
Swagger schema + ui api.
SwaggerSchemaUI "swagger-ui" "swagger.json"
will result into following hierarchy:
/swagger.json /swagger-ui /swagger-ui/index.html /swagger-ui/...
type SwaggerSchemaUI' dir api = api :<|> (dir :> (Get '[HTML] (SwaggerUiHtml dir api) :<|> (("index.html" :> Get '[HTML] (SwaggerUiHtml dir api)) :<|> Raw))) Source #
Use SwaggerSchemaUI'
when you need even more control over
where swagger.json
is served (e.g. subdirectory).
swaggerSchemaUIServer :: Server api ~ Handler Swagger => Swagger -> Server (SwaggerSchemaUI' dir api) Source #
Serve Swagger UI on /dir
using api
as a Swagger spec source.
swaggerSchemaUIServer :: Swagger -> Server (SwaggerSchemaUI schema dir)
jensolegSwaggerSchemaUIServer :: Server api ~ Handler Swagger => Swagger -> Server (SwaggerSchemaUI' dir api) Source #
Serve alternative Swagger UI.
Internals
data SwaggerUiHtml dir api Source #
Index file for swagger ui.
It's configured by the location of swagger schema and directory it lives under.
Implementation detail: the index.html
is prepopulated with parameters
to find schema file automatically.
swaggerSchemaUIServerImpl :: Server api ~ Handler Swagger => Text -> [(FilePath, ByteString)] -> Swagger -> Server (SwaggerSchemaUI' dir api) Source #
Official swagger ui
swaggerUiFiles :: [(FilePath, ByteString)] Source #
jensoleg theme
jensolegFiles :: [(FilePath, ByteString)] Source #