| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Servant.OpenApi.Internal
Contents
Synopsis
- class HasOpenApi (api :: k) where
- subOperations :: (IsSubAPI sub api, HasOpenApi sub) => Proxy sub -> Proxy api -> Traversal' OpenApi Operation
- mkEndpoint :: forall {k1} a (cs :: [Type]) (hs :: [Type]) proxy (method :: k1) (status :: Nat). (ToSchema a, AllAccept cs, AllToResponseHeader hs, OpenApiMethod method, KnownNat status) => FilePath -> proxy (Verb method status cs (Headers hs a)) -> OpenApi
- mkEndpointNoContent :: forall {k1} nocontent (cs :: [Type]) (hs :: [Type]) proxy (method :: k1) (status :: Nat). (AllAccept cs, AllToResponseHeader hs, OpenApiMethod method, KnownNat status) => FilePath -> proxy (Verb method status cs (Headers hs nocontent)) -> OpenApi
- mkEndpointWithSchemaRef :: forall {k1} (cs :: [Type]) (hs :: [Type]) proxy (method :: k1) (status :: Nat) a. (AllAccept cs, AllToResponseHeader hs, OpenApiMethod method, KnownNat status) => Maybe (Referenced Schema) -> FilePath -> proxy (Verb method status cs (Headers hs a)) -> OpenApi
- mkEndpointNoContentVerb :: forall {k1} proxy (method :: k1). OpenApiMethod method => FilePath -> proxy (NoContentVerb method) -> OpenApi
- addParam :: Param -> OpenApi -> OpenApi
- addRequestBody :: RequestBody -> OpenApi -> OpenApi
- markdownCode :: Text -> Text
- addDefaultResponse404 :: ParamName -> OpenApi -> OpenApi
- addDefaultResponse400 :: ParamName -> OpenApi -> OpenApi
- class OpenApiMethod (method :: k) where
- openApiMethod :: proxy method -> Lens' PathItem (Maybe Operation)
- class AllAccept (cs :: k) where
- allContentType :: Proxy cs -> [MediaType]
- class ToResponseHeader (h :: k) where
- toResponseHeader :: Proxy h -> (HeaderName, Header)
- class AllToResponseHeader (hs :: k) where
Documentation
class HasOpenApi (api :: k) where Source #
Generate a OpenApi specification for a servant API.
To generate OpenApi 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
openapi3 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
myOpenApi :: OpenApi
myOpenApi = toOpenApi (Proxy :: Proxy MyAPI)
Methods
toOpenApi :: Proxy api -> OpenApi Source #
Generate a OpenApi specification for a servant API.
Instances
Arguments
| :: (IsSubAPI sub api, HasOpenApi sub) | |
| => Proxy sub | Part of a servant API. |
| -> Proxy api | The whole servant API. |
| -> Traversal' OpenApi Operation |
All operations of sub API.
This is similar to but ensures that operations
indeed belong to the API at compile time.operationsOf
Arguments
| :: forall {k1} a (cs :: [Type]) (hs :: [Type]) proxy (method :: k1) (status :: Nat). (ToSchema a, AllAccept cs, AllToResponseHeader hs, OpenApiMethod method, KnownNat status) | |
| => FilePath | Endpoint path. |
| -> proxy (Verb method status cs (Headers hs a)) | Method, content-types, headers and response. |
| -> OpenApi |
Make a singleton OpenApi spec (with only one endpoint).
For endpoints with no content see mkEndpointNoContent.
Arguments
| :: forall {k1} nocontent (cs :: [Type]) (hs :: [Type]) proxy (method :: k1) (status :: Nat). (AllAccept cs, AllToResponseHeader hs, OpenApiMethod method, KnownNat status) | |
| => FilePath | Endpoint path. |
| -> proxy (Verb method status cs (Headers hs nocontent)) | Method, content-types, headers and response. |
| -> OpenApi |
Make a singletone OpenApi spec (with only one endpoint) and with no content schema.
mkEndpointWithSchemaRef :: forall {k1} (cs :: [Type]) (hs :: [Type]) proxy (method :: k1) (status :: Nat) a. (AllAccept cs, AllToResponseHeader hs, OpenApiMethod method, KnownNat status) => Maybe (Referenced Schema) -> FilePath -> proxy (Verb method status cs (Headers hs a)) -> OpenApi Source #
Like but with explicit schema reference.
Unlike mkEndpoint this function does not update mkEndpoint.definitions
mkEndpointNoContentVerb Source #
Arguments
| :: forall {k1} proxy (method :: k1). OpenApiMethod method | |
| => FilePath | Endpoint path. |
| -> proxy (NoContentVerb method) | Method |
| -> OpenApi |
addRequestBody :: RequestBody -> OpenApi -> OpenApi Source #
Add RequestBody to every operations in the spec.
markdownCode :: Text -> Text Source #
Format given text as inline code in Markdown.
class OpenApiMethod (method :: k) where Source #
Methods, available for OpenApi.
Instances
| OpenApiMethod 'DELETE Source # | |
Defined in Servant.OpenApi.Internal | |
| OpenApiMethod 'GET Source # | |
Defined in Servant.OpenApi.Internal | |
| OpenApiMethod 'HEAD Source # | |
Defined in Servant.OpenApi.Internal | |
| OpenApiMethod 'OPTIONS Source # | |
Defined in Servant.OpenApi.Internal | |
| OpenApiMethod 'PATCH Source # | |
Defined in Servant.OpenApi.Internal | |
| OpenApiMethod 'POST Source # | |
Defined in Servant.OpenApi.Internal | |
| OpenApiMethod 'PUT Source # | |
Defined in Servant.OpenApi.Internal | |
class AllAccept (cs :: k) where Source #
Methods
allContentType :: Proxy cs -> [MediaType] Source #
Instances
| AllAccept ('[] :: [a]) Source # | |
Defined in Servant.OpenApi.Internal Methods allContentType :: Proxy ('[] :: [a]) -> [MediaType] Source # | |
| (Accept c, AllAccept cs) => AllAccept (c ': cs :: [a]) Source # | |
Defined in Servant.OpenApi.Internal Methods allContentType :: Proxy (c ': cs) -> [MediaType] Source # | |
class ToResponseHeader (h :: k) where Source #
Methods
toResponseHeader :: Proxy h -> (HeaderName, Header) Source #
Instances
| (KnownSymbol sym, ToParamSchema a) => ToResponseHeader (Header sym a :: Type) Source # | |
Defined in Servant.OpenApi.Internal Methods toResponseHeader :: Proxy (Header sym a) -> (HeaderName, Header) Source # | |
class AllToResponseHeader (hs :: k) where Source #
Methods
toAllResponseHeaders :: Proxy hs -> InsOrdHashMap HeaderName Header Source #
Instances
| AllToResponseHeader hs => AllToResponseHeader (HList hs :: Type) Source # | |
Defined in Servant.OpenApi.Internal Methods toAllResponseHeaders :: Proxy (HList hs) -> InsOrdHashMap HeaderName Header Source # | |
| AllToResponseHeader ('[] :: [a]) Source # | |
Defined in Servant.OpenApi.Internal Methods toAllResponseHeaders :: Proxy ('[] :: [a]) -> InsOrdHashMap HeaderName Header Source # | |
| (ToResponseHeader h, AllToResponseHeader hs) => AllToResponseHeader (h ': hs :: [a]) Source # | |
Defined in Servant.OpenApi.Internal Methods toAllResponseHeaders :: Proxy (h ': hs) -> InsOrdHashMap HeaderName Header Source # | |
Orphan instances
| (Typeable (WithStatus s a), ToSchema a) => ToSchema (WithStatus s a) Source # | |
Methods declareNamedSchema :: Proxy (WithStatus s a) -> Declare (Definitions Schema) NamedSchema Source # | |