servant-swagger-ui-0.3.0.3.13.2: Servant swagger ui

Copyright(C) 2016-2018 Oleg Grenrus
LicenseBSD-3-Clause
MaintainerOleg Grenrus <oleg.grenrus@iki.fi>
Safe HaskellNone
LanguageHaskell2010

Servant.Swagger.UI

Contents

Description

Provides SwaggerUI and corresponding swaggerSchemaUIServer to embed swagger ui into the application.

All of the 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

Synopsis

Swagger UI API

type SwaggerSchemaUI (dir :: Symbol) (schema :: Symbol) = SwaggerSchemaUI' dir ((:>) Symbol schema (Get ((:) * JSON ([] *)) Swagger)) #

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 :: Symbol) api = (:<|>) api ((:>) Symbol dir ((:<|>) (Get ((:) * HTML ([] *)) (SwaggerUiHtml dir api)) ((:<|>) ((:>) Symbol "index.html" (Get ((:) * HTML ([] *)) (SwaggerUiHtml dir api))) Raw))) #

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)

Official swagger ui