api-tools-0.5: DSL for generating API boilerplate and docs

Safe HaskellNone
LanguageHaskell2010

Data.API.Types

Synopsis

Documentation

type API = [Thing] Source

an API spec is made up of a list of type/element specs, each specifying a Haskell type and JSON wrappers

data Thing Source

Instances

Show Thing 
ToJSON Thing 
FromJSON Thing 
FromJSONWithErrs Thing

Generate an API spec from the JSON

data APINode Source

Specifies an individual element/type of the API

Constructors

APINode 

Fields

anName :: TypeName

name of Haskell type

anComment :: MDComment

comment describing type in Markdown

anPrefix :: Prefix

distinct short prefix (see below)

anSpec :: Spec

the type specification

anConvert :: Conversion

optional conversion functions

newtype TypeName Source

TypeName must contain a valid Haskell type constructor

Constructors

TypeName 

Fields

_TypeName :: String
 

newtype FieldName Source

FieldName identifies recod fields and union alternatives must contain a valid identifier valid in Haskell and any API client wrappers (e.g., if Ruby wrappers are to be generated the names should easily map into Ruby)

Constructors

FieldName 

Fields

_FieldName :: String
 

type MDComment = String Source

Markdown comments are represented by strings

type Prefix = CI String Source

a distinct case-insensitive short prefix used to form unique record field names and data constructors:

  • must be a valid Haskell identifier

    • must be unique within the API

data Spec Source

type/element specs are either simple type isomorphisms of basic JSON types, records, unions or enumerated types

data SpecNewtype Source

SpecNewtype elements are isomorphisms of string, inetgers or booleans

Constructors

SpecNewtype 

data SpecRecord Source

SpecRecord is your classsic product type.

Constructors

SpecRecord 

Fields

srFields :: [(FieldName, FieldType)]
 

data FieldType Source

In addition to the type and comment, record fields may carry a flag indicating that they are read-only, and may have a default value, which must be of a compatible type.

data SpecUnion Source

SpecUnion is your classsic union type

Constructors

SpecUnion 

Fields

suFields :: [(FieldName, (APIType, MDComment))]
 

data SpecEnum Source

SpecEnum is your classic enumerated type

Constructors

SpecEnum 

Fields

seAlts :: [(FieldName, MDComment)]
 

data APIType Source

Type is either a list, Maybe, a named element of the API or a basic type

Constructors

TyList APIType

list elements are types

TyMaybe APIType

Maybe elements are types

TyName TypeName

the referenced type must be defined by the API

TyBasic BasicType

a JSON string, int, bool etc.

TyJSON

a generic JSON value

Instances

Eq APIType 
Show APIType 
IsString APIType

It is sometimes helpful to write a type name directly as a string

ToJSON APIType 
FromJSON APIType 
PP APIType 

data BasicType Source

the basic JSON types (N.B., no floating point numbers, yet)

Constructors

BTstring

a JSON UTF-8 string

BTbinary

a base-64-encoded byte string

BTbool

a JSON bool

BTint

a JSON integral number

BTutc

a JSON UTC string

data RegEx Source

Constructors

RegEx 

Fields

re_text :: Text
 
re_regex :: Regex
 

newtype Binary Source

Binary data is represented in JSON format as a base64-encoded string

Constructors

Binary 

Fields

_Binary :: ByteString
 

defaultValueAsJsValue :: DefaultValue -> Value Source

Convert a default value to an Aeson Value. This differs from toJSON as it will not round-trip with fromJSON: UTC default values are turned into strings.