servant-swagger-1.1.5: Generate Swagger specification for your servant API.

Safe HaskellNone
LanguageHaskell2010

Servant.Swagger.Internal

Synopsis

Documentation

class HasSwagger api where Source #

Generate a Swagger specification for a servant API.

To generate Swagger specification, your data types need ToParamSchema and/or ToSchema instances.

ToParamSchema is used for Capture, QueryParam and Header. ToSchema is used for ReqBody and response data types.

You can easily derive those instances via Generic. For more information, refer to swagger2 documentation.

Example:

newtype Username = Username String deriving (Generic, ToText)

instance ToParamSchema Username

data User = User
  { username :: Username
  , fullname :: String
  } deriving (Generic)

instance ToJSON User
instance ToSchema User

type MyAPI = QueryParam "username" Username :> Get '[JSON] User

mySwagger :: Swagger
mySwagger = toSwagger (Proxy :: Proxy MyAPI)

Minimal complete definition

toSwagger

Methods

toSwagger :: Proxy api -> Swagger Source #

Generate a Swagger specification for a servant API.

Instances

HasSwagger * Raw Source # 

Methods

toSwagger :: Proxy Raw api -> Swagger Source #

HasSwagger * EmptyAPI Source # 
(HasSwagger * a, HasSwagger * b) => HasSwagger * ((:<|>) a b) Source # 

Methods

toSwagger :: Proxy (a :<|> b) api -> Swagger Source #

HasSwagger * sub => HasSwagger * (WithNamedContext x c sub) Source #

WithNamedContext combinator does not change our specification at all.

Methods

toSwagger :: Proxy (WithNamedContext x c sub) api -> Swagger Source #

HasSwagger * sub => HasSwagger * ((:>) * HttpVersion sub) Source #

HttpVersion combinator does not change our specification at all.

Methods

toSwagger :: Proxy ((* :> HttpVersion) sub) api -> Swagger Source #

(ToSchema a, AllAccept [*] cs, HasSwagger * sub, KnownSymbol (FoldDescription mods)) => HasSwagger * ((:>) * (ReqBody' mods cs a) sub) Source # 

Methods

toSwagger :: Proxy ((* :> ReqBody' mods cs a) sub) api -> Swagger Source #

HasSwagger * sub => HasSwagger * ((:>) * RemoteHost sub) Source #

RemoteHost combinator does not change our specification at all.

Methods

toSwagger :: Proxy ((* :> RemoteHost) sub) api -> Swagger Source #

(KnownSymbol sym, ToParamSchema a, HasSwagger * sub, SBoolI (FoldRequired mods), KnownSymbol (FoldDescription mods)) => HasSwagger * ((:>) * (QueryParam' mods sym a) sub) Source # 

Methods

toSwagger :: Proxy ((* :> QueryParam' mods sym a) sub) api -> Swagger Source #

(KnownSymbol sym, ToParamSchema a, HasSwagger * sub) => HasSwagger * ((:>) * (QueryParams sym a) sub) Source # 

Methods

toSwagger :: Proxy ((* :> QueryParams sym a) sub) api -> Swagger Source #

(KnownSymbol sym, HasSwagger * sub) => HasSwagger * ((:>) * (QueryFlag sym) sub) Source # 

Methods

toSwagger :: Proxy ((* :> QueryFlag sym) sub) api -> Swagger Source #

(KnownSymbol sym, ToParamSchema a, HasSwagger * sub, SBoolI (FoldRequired mods), KnownSymbol (FoldDescription mods)) => HasSwagger * ((:>) * (Header' * mods sym a) sub) Source # 

Methods

toSwagger :: Proxy ((* :> Header' * mods sym a) sub) api -> Swagger Source #

HasSwagger * sub => HasSwagger * ((:>) * IsSecure sub) Source #

IsSecure combinator does not change our specification at all.

Methods

toSwagger :: Proxy ((* :> IsSecure) sub) api -> Swagger Source #

(KnownSymbol desc, HasSwagger * api) => HasSwagger * ((:>) * (Summary desc) api) Source # 

Methods

toSwagger :: Proxy ((* :> Summary desc) api) api -> Swagger Source #

(KnownSymbol desc, HasSwagger * api) => HasSwagger * ((:>) * (Description desc) api) Source # 

Methods

toSwagger :: Proxy ((* :> Description desc) api) api -> Swagger Source #

(KnownSymbol sym, ToParamSchema a, HasSwagger * sub, KnownSymbol (FoldDescription mods)) => HasSwagger * ((:>) * (Capture' mods sym a) sub) Source # 

Methods

toSwagger :: Proxy ((* :> Capture' mods sym a) sub) api -> Swagger Source #

(KnownSymbol sym, ToParamSchema a, HasSwagger * sub) => HasSwagger * ((:>) * (CaptureAll sym a) sub) Source #

Swagger Spec doesn't have a notion of CaptureAll, this instance is the best effort.

Methods

toSwagger :: Proxy ((* :> CaptureAll sym a) sub) api -> Swagger Source #

HasSwagger * sub => HasSwagger * ((:>) * Vault sub) Source #

Vault combinator does not change our specification at all.

Methods

toSwagger :: Proxy ((* :> Vault) sub) api -> Swagger Source #

(KnownSymbol sym, HasSwagger * sub) => HasSwagger * ((:>) Symbol sym sub) Source # 

Methods

toSwagger :: Proxy ((Symbol :> sym) sub) api -> Swagger Source #

(AllAccept [*] cs, KnownNat status, SwaggerMethod k1 method) => HasSwagger * (Verb k1 method status cs NoContent) Source # 

Methods

toSwagger :: Proxy (Verb k1 method status cs NoContent) api -> Swagger Source #

(ToSchema a, AllAccept [*] cs, KnownNat status, SwaggerMethod k1 method) => HasSwagger * (Verb k1 method status cs a) Source # 

Methods

toSwagger :: Proxy (Verb k1 method status cs a) api -> Swagger Source #

(AllAccept [*] cs, AllToResponseHeader [*] hs, KnownNat status, SwaggerMethod k1 method) => HasSwagger * (Verb k1 method status cs (Headers hs NoContent)) Source # 

Methods

toSwagger :: Proxy (Verb k1 method status cs (Headers hs NoContent)) api -> Swagger Source #

(ToSchema a, AllAccept [*] cs, AllToResponseHeader [*] hs, KnownNat status, SwaggerMethod k1 method) => HasSwagger * (Verb k1 method status cs (Headers hs a)) Source # 

Methods

toSwagger :: Proxy (Verb k1 method status cs (Headers hs a)) api -> Swagger Source #

subOperations Source #

Arguments

:: (IsSubAPI sub api, HasSwagger sub) 
=> Proxy sub

Part of a servant API.

-> Proxy api

The whole servant API.

-> Traversal' Swagger Operation 

All operations of sub API. This is similar to operationsOf but ensures that operations indeed belong to the API at compile time.

mkEndpoint Source #

Arguments

:: (ToSchema a, AllAccept cs, AllToResponseHeader hs, SwaggerMethod method, KnownNat status) 
=> FilePath

Endpoint path.

-> proxy (Verb method status cs (Headers hs a))

Method, content-types, headers and response.

-> Swagger 

Make a singleton Swagger spec (with only one endpoint). For endpoints with no content see mkEndpointNoContent.

mkEndpointNoContent Source #

Arguments

:: (AllAccept cs, AllToResponseHeader hs, SwaggerMethod method, KnownNat status) 
=> FilePath

Endpoint path.

-> proxy (Verb method status cs (Headers hs nocontent))

Method, content-types, headers and response.

-> Swagger 

Make a singletone Swagger spec (with only one endpoint) and with no content schema.

mkEndpointWithSchemaRef :: forall cs hs proxy method status a. (AllAccept cs, AllToResponseHeader hs, SwaggerMethod method, KnownNat status) => Maybe (Referenced Schema) -> FilePath -> proxy (Verb method status cs (Headers hs a)) -> Swagger Source #

Like mkEndpoint but with explicit schema reference. Unlike mkEndpoint this function does not update definitions.

addParam :: Param -> Swagger -> Swagger Source #

Add parameter to every operation in the spec.

addConsumes :: [MediaType] -> Swagger -> Swagger Source #

Add accepted content types to every operation in the spec.

markdownCode :: Text -> Text Source #

Format given text as inline code in Markdown.

class AllAccept cs where Source #

Minimal complete definition

allContentType

Instances

AllAccept [k] ([] k) Source # 

Methods

allContentType :: Proxy [k] cs -> [MediaType] Source #

(Accept a c, AllAccept [a] cs) => AllAccept [a] ((:) a c cs) Source # 

Methods

allContentType :: Proxy ((a ': c) cs) cs -> [MediaType] Source #

class ToResponseHeader h where Source #

Minimal complete definition

toResponseHeader

Instances