servant-swagger-ui-0.1.0.2.1.4: Servant swagger ui

Copyright(C) 2016 Oleg Grenrus
LicenseBSD3
MaintainerOleg Grenrus <oleg.grenrus@iki.fi>
Safe HaskellNone
LanguageHaskell2010

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

Synopsis

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 

Instances

(IsElem endpoint api, HasLink * endpoint, (~) * (MkLink * endpoint) URI) => ToMarkup (SwaggerUiHtml endpoint api) Source # 

Methods

toMarkup :: SwaggerUiHtml endpoint api -> Markup #

preEscapedToMarkup :: SwaggerUiHtml endpoint api -> Markup #