openapi3-code-generator-0.1.0.6: OpenAPI3 Haskell Client Code Generator

Safe HaskellNone
LanguageHaskell2010

OpenAPI.Common

Description

This module serves the purpose of defining common functionality which remains the same across all OpenAPI specifications.

Synopsis

Documentation

data Configuration s Source #

An operation can and must be configured with data, which may be common for many operations.

This configuration consists of information about the server URL and the used security scheme.

In OpenAPI these information can be defined

  • Root level
  • Path level
  • Operation level

To get started, the defaultConfiguration can be used and changed accordingly.

Note that it is possible that BearerAuthenticationSecurityScheme is not available because it is not a security scheme in the OpenAPI specification.

defaultConfiguration
  { configSecurityScheme = BearerAuthenticationSecurityScheme "token" }
Instances
Eq s => Eq (Configuration s) Source # 
Instance details

Defined in OpenAPI.Common

Ord s => Ord (Configuration s) Source # 
Instance details

Defined in OpenAPI.Common

Show s => Show (Configuration s) Source # 
Instance details

Defined in OpenAPI.Common

Generic (Configuration s) Source # 
Instance details

Defined in OpenAPI.Common

Associated Types

type Rep (Configuration s) :: Type -> Type #

type Rep (Configuration s) Source # 
Instance details

Defined in OpenAPI.Common

type Rep (Configuration s) = D1 (MetaData "Configuration" "OpenAPI.Common" "openapi3-code-generator-0.1.0.6-6iC1yCYlehZL3mtXad2QKS" False) (C1 (MetaCons "Configuration" PrefixI True) (S1 (MetaSel (Just "configBaseURL") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text) :*: S1 (MetaSel (Just "configSecurityScheme") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 s)))

doCallWithConfiguration Source #

Arguments

:: (MonadHTTP m, SecurityScheme s) 
=> Configuration s

Configuration options like base URL and security scheme

-> Text

HTTP method (GET, POST, etc.)

-> Text

Path to append to the base URL (path parameters should already be replaced)

-> [(Text, Maybe String)]

Query parameters

-> m (Either HttpException (Response ByteString))

The raw response from the server

This is the main functionality of this module

It makes a concrete Call to a Server without a body

doCallWithConfigurationM :: (MonadHTTP m, SecurityScheme s) => Text -> Text -> [(Text, Maybe String)] -> ReaderT (Configuration s) m (Either HttpException (Response ByteString)) Source #

Same as doCallWithConfiguration but run in a ReaderT environment which contains the configuration. This is useful if multiple calls have to be executed with the same configuration.

doBodyCallWithConfiguration Source #

Arguments

:: (MonadHTTP m, SecurityScheme s, ToJSON body) 
=> Configuration s

Configuration options like base URL and security scheme

-> Text

HTTP method (GET, POST, etc.)

-> Text

Path to append to the base URL (path parameters should already be replaced)

-> [(Text, Maybe String)]

Query parameters

-> Maybe body

Request body

-> RequestBodyEncoding

JSON or form data deepobjects

-> m (Either HttpException (Response ByteString))

The raw response from the server

This is the main functionality of this module

It makes a concrete Call to a Server with a body

doBodyCallWithConfigurationM :: (MonadHTTP m, SecurityScheme s, ToJSON body) => Text -> Text -> [(Text, Maybe String)] -> Maybe body -> RequestBodyEncoding -> ReaderT (Configuration s) m (Either HttpException (Response ByteString)) Source #

Same as doBodyCallWithConfiguration but run in a ReaderT environment which contains the configuration. This is useful if multiple calls have to be executed with the same configuration.

runWithConfiguration :: SecurityScheme s => Configuration s -> ReaderT (Configuration s) m a -> m a Source #

Run the ReaderT monad with a specified configuration

Note: This is just flip runReaderT.

class Monad m => MonadHTTP m where Source #

Abstracts the usage of httpBS away, so that it can be used for testing

Instances
MonadHTTP IO Source #

This instance is the default instance used for production code

Instance details

Defined in OpenAPI.Common

MonadHTTP m => MonadHTTP (ReaderT r m) Source # 
Instance details

Defined in OpenAPI.Common

stringifyModel :: StringifyModel a => a -> String Source #

Stringifies a showable value

>>> stringifyModel "Test"
"Test"
>>> stringifyModel 123
"123"

class Show a => StringifyModel a Source #

This type class makes the code generation for URL parameters easier as it allows to stringify a value

The Show class is not sufficient as strings should not be stringified with quotes.

Minimal complete definition

stringifyModel

Instances
Show a => StringifyModel a Source # 
Instance details

Defined in OpenAPI.Common

Methods

stringifyModel :: a -> String Source #

StringifyModel Text Source # 
Instance details

Defined in OpenAPI.Common

StringifyModel String Source # 
Instance details

Defined in OpenAPI.Common

class SecurityScheme s where Source #

Allows to specify an authentication scheme for requests done with doCallWithConfiguration

This can be used to define custom schemes as well

Instances
SecurityScheme AnonymousSecurityScheme Source #

Instance for the anonymous scheme which does not alter the request in any way

Instance details

Defined in OpenAPI.Common

data AnonymousSecurityScheme Source #

The default authentication scheme which does not add any authentication information

Instances
SecurityScheme AnonymousSecurityScheme Source #

Instance for the anonymous scheme which does not alter the request in any way

Instance details

Defined in OpenAPI.Common

data RequestBodyEncoding Source #

Defines how a request body is encoded

Constructors

RequestBodyEncodingJSON

Encode the body as JSON

RequestBodyEncodingFormData

Encode the body as form data