| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Servant.Swagger.Internal
Synopsis
- class HasSwagger api where
- subOperations :: (IsSubAPI sub api, HasSwagger sub) => Proxy sub -> Proxy api -> Traversal' Swagger Operation
- mkEndpoint :: forall a cs hs proxy method status. (ToSchema a, AllAccept cs, AllToResponseHeader hs, SwaggerMethod method, KnownNat status) => FilePath -> proxy (Verb method status cs (Headers hs a)) -> Swagger
- mkEndpointNoContent :: forall nocontent cs hs proxy method status. (AllAccept cs, AllToResponseHeader hs, SwaggerMethod method, KnownNat status) => FilePath -> proxy (Verb method status cs (Headers hs nocontent)) -> Swagger
- 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
- addParam :: Param -> Swagger -> Swagger
- addConsumes :: [MediaType] -> Swagger -> Swagger
- markdownCode :: Text -> Text
- addDefaultResponse404 :: ParamName -> Swagger -> Swagger
- addDefaultResponse400 :: ParamName -> Swagger -> Swagger
- class SwaggerMethod method where
- class AllAccept cs where
- class ToResponseHeader h where
- class AllToResponseHeader hs where
Documentation
class HasSwagger api where #
Generate a Swagger specification for a servant API.
To generate Swagger specification, your data types need
and/or ToParamSchema instances.ToSchema
is used for ToParamSchema, Capture and QueryParam.
Header is used for ToSchema and response data types.ReqBody
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
Instances
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 but ensures that operations
indeed belong to the API at compile time.operationsOf
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.
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 #
Like but with explicit schema reference.
Unlike mkEndpoint this function does not update mkEndpoint.definitions
addConsumes :: [MediaType] -> Swagger -> Swagger #
Add accepted content types to every operation in the spec.
markdownCode :: Text -> Text #
Format given text as inline code in Markdown.
addDefaultResponse404 :: ParamName -> Swagger -> Swagger #
addDefaultResponse400 :: ParamName -> Swagger -> Swagger #
class SwaggerMethod method where #
Methods, available for Swagger.
Minimal complete definition
Instances
| SwaggerMethod PATCH # | |
Defined in Servant.Swagger.Internal | |
| SwaggerMethod OPTIONS # | |
Defined in Servant.Swagger.Internal | |
| SwaggerMethod DELETE # | |
Defined in Servant.Swagger.Internal | |
| SwaggerMethod PUT # | |
Defined in Servant.Swagger.Internal | |
| SwaggerMethod HEAD # | |
Defined in Servant.Swagger.Internal | |
| SwaggerMethod POST # | |
Defined in Servant.Swagger.Internal | |
| SwaggerMethod GET # | |
Defined in Servant.Swagger.Internal | |
Minimal complete definition
Methods
allContentType :: Proxy cs -> [MediaType] #
Instances
| AllAccept ([] :: [k]) # | |
Defined in Servant.Swagger.Internal Methods allContentType :: Proxy [] -> [MediaType] # | |
| (Accept c, AllAccept cs) => AllAccept (c ': cs :: [a]) # | |
Defined in Servant.Swagger.Internal Methods allContentType :: Proxy (c ': cs) -> [MediaType] # | |
class ToResponseHeader h where #
Minimal complete definition
Methods
toResponseHeader :: Proxy h -> (HeaderName, Header) #
Instances
| (KnownSymbol sym, ToParamSchema a) => ToResponseHeader (Header sym a :: *) # | |
Defined in Servant.Swagger.Internal Methods toResponseHeader :: Proxy (Header sym a) -> (HeaderName, Header0) # | |
class AllToResponseHeader hs where #
Minimal complete definition
Methods
toAllResponseHeaders :: Proxy hs -> InsOrdHashMap HeaderName Header #
Instances
| AllToResponseHeader ([] :: [k]) # | |
Defined in Servant.Swagger.Internal Methods toAllResponseHeaders :: Proxy [] -> InsOrdHashMap HeaderName Header # | |
| AllToResponseHeader hs => AllToResponseHeader (HList hs :: *) # | |
Defined in Servant.Swagger.Internal Methods toAllResponseHeaders :: Proxy (HList hs) -> InsOrdHashMap HeaderName Header # | |
| (ToResponseHeader h, AllToResponseHeader hs) => AllToResponseHeader (h ': hs :: [a]) # | |
Defined in Servant.Swagger.Internal Methods toAllResponseHeaders :: Proxy (h ': hs) -> InsOrdHashMap HeaderName Header # | |