Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
OpenAPI.Generate.Internal.Operation
Description
Helpers for the generation of the operation functions
Synopsis
- getResponseObject :: Referencable ResponseObject -> Generator (Maybe (ResponseObject, [Text]))
- getResponseSchema :: ResponseObject -> Generator (Maybe Schema, [Text])
- defineOperationFunction :: Bool -> Name -> ParameterCardinality -> Text -> Text -> Maybe RequestBodyDefinition -> Q Exp -> Generator (Q Doc)
- getParameterDescription :: ParameterObject -> Generator Text
- generateParameterTypeFromOperation :: Text -> OperationObject -> Generator ParameterCardinality
- getParametersTypeForSignature :: [Q Type] -> Name -> Name -> Q Type
- getParametersTypeForSignatureWithMonadTransformer :: [Q Type] -> Name -> Name -> Q Type
- getOperationName :: Text -> Text -> OperationObject -> Generator Name
- getOperationDescription :: OperationObject -> Text
- getBodySchemaFromOperation :: OperationObject -> Generator (Maybe RequestBodyDefinition, [Text])
- generateParameterizedRequestPath :: [(Q Exp, ParameterObject)] -> Text -> Q Exp
- generateQueryParams :: [(Q Exp, ParameterObject)] -> Q Exp
- shouldGenerateRequestBody :: Maybe RequestBodyDefinition -> Generator Bool
- data RequestBodyDefinition = RequestBodyDefinition {}
- data ParameterTypeDefinition = ParameterTypeDefinition {}
- data ParameterCardinality
Documentation
getResponseObject :: Referencable ResponseObject -> Generator (Maybe (ResponseObject, [Text])) Source #
Resolve a possibly referenced response to a concrete value.
A warning is logged if the reference is not found.
getResponseSchema :: ResponseObject -> Generator (Maybe Schema, [Text]) Source #
Extracts the response Schema
from a ResponseObject
.
A warning is logged if the response does not contain one of the supported media types.
defineOperationFunction Source #
Arguments
:: Bool | Should the configuration be passed explicitly as parameter? |
-> Name | How the function should be called |
-> ParameterCardinality | The parameters |
-> Text | The request path. It may contain placeholders in the form my{var}path |
-> Text | HTTP Method (POST,GET,etc.) |
-> Maybe RequestBodyDefinition | Schema of body |
-> Q Exp | An expression used to transform the response from |
-> Generator (Q Doc) | Function body definition in TH |
Defines the body of an Operation function The Operation function calls an generall HTTP function all Parameters are arguments to the function
getParameterDescription :: ParameterObject -> Generator Text Source #
Get a description of a parameter object (the name and if available the description from the specification)
generateParameterTypeFromOperation :: Text -> OperationObject -> Generator ParameterCardinality Source #
Generates the parameter type for an operation. See ParameterCardinality
for further information.
getParametersTypeForSignature :: [Q Type] -> Name -> Name -> Q Type Source #
Gets the Type definition dependent on the number of parameters/types A monadic name for which its forall structure is defined outside this function can be given
[t|OC.Configuration -> Int -> $(varT monadName) ($(responseType) $(responseInnerType))|] = getParametersTypeForSignature conT ''Int
getParametersTypeForSignatureWithMonadTransformer :: [Q Type] -> Name -> Name -> Q Type Source #
Same as getParametersTypeForSignature
but with the configuration in ReaderT
instead of a parameter
getOperationName :: Text -> Text -> OperationObject -> Generator Name Source #
Constructs the name of an operation.
If an operationId
is available, this is the primary choice.
If it is not available, the id is constructed based on the request path and method.
getOperationDescription :: OperationObject -> Text Source #
Extracts a description from an OperationObject
.
If available, the description is used, the summary otherwise.
If neither is available, an empty description is used.
getBodySchemaFromOperation :: OperationObject -> Generator (Maybe RequestBodyDefinition, [Text]) Source #
Extracts the request body schema from an operation and the encoding which should be used on the body data.
generateParameterizedRequestPath :: [(Q Exp, ParameterObject)] -> Text -> Q Exp Source #
Resolves placeholders in paths with dynamic expressions
"my{var}path" -> "my" ++ myVar ++ "/path"
If the placeholder is at the end or at the beginning an empty string gets appended
generateQueryParams :: [(Q Exp, ParameterObject)] -> Q Exp Source #
Generates query params in the form of [(Text,ByteString)]
shouldGenerateRequestBody :: Maybe RequestBodyDefinition -> Generator Bool Source #
Checks if a request body should be generated based on the CLI options and if the body type is an empty object
data RequestBodyDefinition Source #
Extracted request body information which can be used for code generation
data ParameterTypeDefinition Source #
Defines the type of a parameter bundle including the information to access the specific parameters
data ParameterCardinality Source #
Represents the number of (supported) parameters and the generated types which result of it
- No type is generated when no parameters are present
- Only the type of the parameter is generated if a single parameter is present
- A combined parameter type is generated for multiple parameters