harmony-0.1.1.0: A web service specification compiler that generates implementation and tests.

Safe HaskellNone
LanguageHaskell2010

TypeCheck.ApiSpec

Description

Defines an api spec (to be built after the static checking of the AST) and helper methods over it.

Synopsis

Documentation

type Route = String Source

The route of a resource.

type EnumValue = String Source

An enum value.

type EnumInfo = [EnumValue] Source

An enum is a list of values.

data Modifier Source

A field modifier.

Constructors

Hidden

The field will not be returned when read

Immutable

The field cannot be modified

Required

The field can't be absent

PrimaryKey

The field is the primary key (thus Unique as well)

Unique

The field can't have repeated values throughout the collection

UserLogin

The field value will contain the user's login

newtype FieldInfo Source

A field has a type, an identifier and a set of modifiers.

Constructors

FI (Id, Type, Set Modifier) 

type StructInfo = [FieldInfo] Source

A struct is a list of fields.

type ResourceInfo = (Route, Writable) Source

A resource has a route and a write mode.

data Type Source

A type can be a primitive one (int, long, double, bool...), an enum, a struct, or a list of another type.

type Enums = Map Id EnumInfo Source

Map from enum id to its info.

type Structs = [(Id, StructInfo)] Source

Map from struct id to its info.

type Writable = Bool Source

Writable is a boolean type.

data ApiSpec Source

The spec of an api is a set of enums and structs, along with the resources.

Constructors

AS 

Fields

name :: String

Name of the service

version :: String

Version of the service

requiresAuth :: Bool

Whether it should support authentication or not

enums :: Enums

Information about the user defined enums

structs :: Structs

Information about the user defined structs

resources :: Resources

Information about the resources defined

getPrimaryKey Source

Arguments

:: StructInfo

The info of the struct

-> Maybe Id

The result (Nothing if there was no PK defined)

Gets the primary key of a struct if it was specified.

isStructField :: FieldInfo -> Bool Source

Finds out if a fieldinfo is relative to a struct

isStruct :: Type -> Bool Source

Find outs if a type is a struct

strName :: Type -> String Source

Get the name of a struct

nonEmptyString :: Gen String Source

Generates a non-empty arbitrary String.

generateRandomFieldInfo :: [Id] -> [Id] -> Gen FieldInfo Source

Generates an arbitrary FieldInfo, making sure that the ids used for enums and structs are valid.