Safe Haskell | None |
---|
This module provides an interface for generating TH declarations
from an API
. To use it, splice in a call to generate
followed
by one or more calls to generateAPITools
, like so:
$(generate myAPI) $(generateAPITools [enumTool, jsonTool, quickCheckTool] myAPI)
If you wish to override any of the instances generated by the
tools, you can do so by writing instance declarations after the
call to generate
but before the call to generateAPITools
.
- generate :: API -> Q [Dec]
- generateAPITools :: API -> [APITool] -> Q [Dec]
- generateAPIToolsWith :: ToolSettings -> API -> [APITool] -> Q [Dec]
- defaultToolSettings :: ToolSettings
- warnOnOmittedInstance :: ToolSettings -> Bool
- enumTool :: APITool
- exampleTool :: APITool
- jsonTool :: APITool
- jsonTestsTool :: Name -> APITool
- lensTool :: APITool
- quickCheckTool :: APITool
- safeCopyTool :: APITool
- samplesTool :: Name -> APITool
Documentation
generateAPITools :: API -> [APITool] -> Q [Dec]Source
Apply a list of tools to an API
, generating TH declarations.
See the individual tool descriptions for details. Note that
generate
must be called first, and some tools have dependencies,
which must be included in the same or a preceding call to
generateAPITools
.
Tool settings
generateAPIToolsWith :: ToolSettings -> API -> [APITool] -> Q [Dec]Source
Apply a list of tools to an API
, generating TH declarations.
This form allows the ToolSettings
to be overridden.
defaultToolSettings :: ToolSettingsSource
Default settings designed to be overridden.
warnOnOmittedInstance :: ToolSettings -> BoolSource
Generate a warning when an instance declaration is omitted because it already exists
Individual tools
Tool to generate the maps between enumerations and Text
strings
named by text_enum_nm
and map_enum_nm
.
Tool to generate Example
instances for types generated by
datatypesTool
. This depends on quickCheckTool
.
Tool to generate ToJSON
and FromJSONWithErrs
instances for
types generated by datatypesTool
. This depends on enumTool
.
jsonTestsTool :: Name -> APIToolSource
quickCheckTool :: APIToolSource
Tool to generate Arbitrary
instances for generated types.
Tool to derive SafeCopy
instances for generated types. At
present, this derives only base version instances.
samplesTool :: Name -> APIToolSource
Generate a list of (type name, sample generator) pairs
corresponding to each type in the API, with samples encoded as
JSON. This depends on the Example
instances generated by
exampleTool
. It generates something like this:
samples :: [(String, Gen Value)] samples = [("Foo", fmap toJSON (example :: Gen Foo)), ... ]