aeson-schema-0.4.0.0: Haskell JSON schema validator and parser generator

Safe HaskellNone
LanguageHaskell98

Data.Aeson.Schema.CodeGenM

Contents

Synopsis

Documentation

data Declaration Source

A top-level declaration.

Constructors

Declaration Dec (Maybe Text)

Optional textual declaration. This can be used for information (e.g. inline comments) that are not representable in TH.

Comment Text

Comment text

type Code = [Declaration] Source

 Haskell code (without module declaration and imports)

newtype CodeGenM s a Source

Constructors

CodeGenM 

Fields

unCodeGenM :: RWST (Options, s) Code StringSet Q a
 

Instances

MonadWriter Code (CodeGenM s) 
Monad (CodeGenM s) 
Functor (CodeGenM s) 
Applicative (CodeGenM s) 
MonadIO (CodeGenM s)

Generates a record data declaration where the fields may have descriptions for Haddock

Quasi (CodeGenM s) 
MonadReader (Options, s) (CodeGenM s) 

renderDeclaration :: Declaration -> Text Source

 Render a declaration. When a declaration contains both a TH syntax tree and a text representation, the text representation is preferred.

codeGenNewName :: String -> StringSet -> (Name, StringSet) Source

 Generates a fresh name

genRecord Source

Arguments

:: Name

Type and constructor name

-> [(Name, TypeQ, Maybe Text)]

Fields

-> [Name]

Deriving typeclasses

-> Q Declaration 

Customising the codegen

data Options Source

Extra options used for the codegen

Constructors

Options 

Fields

_extraModules :: [String]

Needed modules that are not found by getUsedModules.

_derivingTypeclasses :: [Name]

Classes to put in the deriving clause

_replaceModules :: Map String String

A Map of modules which we should replace with other ones when references to them are found. Useful for example when the codegen is hitting a hidden module that's not already gotten rid of in replaceHiddenModules.

_languageExtensions :: [Text]

List of LANGUAGE extensions to enable in the module. Note that these aren't checked for validity.

_languageExtensions = [ LambdaCase ]
_ghcOptsPragmas :: [Text]

List of OPTIONS_GHC to turn on in the module. Note that these aren't checked for validity.

_ghcOptsPragmas = [ "-fno-warn-name-shadowing" ]
_extraInstances :: Name -> [DecQ]

Supplied a Name of the type in question (after mangling), potentially generate an instance for the type. For example, to generate an empty Enum instance for every data type we make, the user can supply something like

_extraInstances = n -> return $
  instanceD (cxt []) (conT ''Enum appT conT n) []

and to generate no instances, simply use const [].

Instances