json-spec-elm-servant-0.4.2.2: Generated elm code for servant APIs.
Safe HaskellNone
LanguageHaskell2010

Data.JsonSpec.Elm.Servant

Synopsis

Generating Elm Clients

servantDefs :: forall {k} (api :: k). Elmable api => Proxy api -> Set Definition Source #

This function will traverse the api type, generating elm definitions for:

  • Http requests for each endpoint, including encoders and decoders for anonymous elm types.
  • Named Elm types (i.e. Any Specification that is bound to a name using JsonLet
  • Decoders and Encoders for named elm types.

You can consume the resulting Definitions using the elm-syntax:Language.Elm.Pretty module.

generateElm Source #

Arguments

:: forall {k} (api :: k). Elmable api 
=> OsPath

The directory in which to deposit Elm code.

-> Proxy api 
-> IO () 

"Batteries included" way to generate some Elm code on disk in a given a directory. The directory should be dedicated to the generated Elm code and you shouldn't try to store anything else in that directory, Elm files or otherwise.

This function will succeed without error if (and only if) the directory already exists and its contents exactly match what would be generated anyway.

If the files on disk are wrong, then an error is thrown, and the files are unmodified.

If the directory does not exist, then it is created and the Elm code is generated inside the directory, then an error is thrown.

The intent is that you can use this function (thinly wrapped with the appropriate directory and api spec) as the main function for a test suite, where the "test" is that the files on disk are already correct. We throw an error even in the case where we generate files for you because, for instance, you wouldn't want CI to be generating these files when you forgot to check them in in the first place.

Extensions

The symbols in this section are mainly exposed in case you are using some extensions to the standard servant types and need to build some companion extensions to generate proper Elm types for them. For most normal usage you will probably just use generateElm (or possibly servantDefs).

class Elmable (e :: k) where Source #

Class of servant APIs for which Elm client code can be generated.

Methods

endpoints :: [Param] -> Definitions () Source #

Collect all the Elm definitions needed to implement a client for the API. This is called recursively on our walk down the API tree, and the [Param] argument contains all the request parameters (like Capture, ReqBody', etc) that have been encountered so far on whatever particular branch . It will start out empty at the API root.

Instances

Instances details
Elmable (ToServantApi api) => Elmable (NamedRoutes api :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

Methods

endpoints :: [Param] -> Definitions () Source #

(Elmable a, Elmable b) => Elmable (a :<|> b :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

Methods

endpoints :: [Param] -> Definitions () Source #

ReflectMethod method => Elmable (NoContentVerb method :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

Methods

endpoints :: [Param] -> Definitions () Source #

(IsParam a, Elmable b) => Elmable (a :> b :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

Methods

endpoints :: [Param] -> Definitions () Source #

Elmable (NoContentVerb m) => Elmable (Verb m c t NoContent :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

Methods

endpoints :: [Param] -> Definitions () Source #

Elmable (Verb m c t r) => Elmable (Verb m c t (Headers h r) :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

Methods

endpoints :: [Param] -> Definitions () Source #

(HasType (EncodingSpec response), ReflectMethod method) => Elmable (Verb method code types response :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

Methods

endpoints :: [Param] -> Definitions () Source #

class IsParam (a :: k) where Source #

Obtain a value-level request parameter type from the type-level servant parameter type.

Instances

Instances details
KnownSymbol segment => IsParam (segment :: Symbol) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

IsParam (a :: k) Source #

The default instance assumes that the API combinator does not contribute to the parameter list or the "name of the endpoint" in any way. This covers things like Summary and Description, or potentially custom combinators created by the user. In the case of custom combinators, you may need to create an overlapping instance if you wish it to affect the elm function parameters or function name.

Instance details

Defined in Data.JsonSpec.Elm.Servant

KnownSymbol name => IsParam (Capture name tpy :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

KnownSymbol name => IsParam (Header' (Optional ': mods) name a :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

KnownSymbol name => IsParam (Header' (Required ': mods) name a :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

IsParam (Header' mods name a) => IsParam (Header' (other ': mods) name a :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

KnownSymbol name => IsParam (QueryParam' (Optional ': more) name typ :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

KnownSymbol name => IsParam (QueryParam' (Required ': more) name typ :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

IsParam (QueryParam' more name typ) => IsParam (QueryParam' (other ': more) name typ :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

HasType (DecodingSpec a) => IsParam (ReqBody' (Required ': mods) (JSON ': accept) a :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

IsParam (ReqBody' mods '[JSON] a) => IsParam (ReqBody' (other ': mods) (JSON ': accept) a :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

IsParam (ReqBody' mods accept a) => IsParam (ReqBody' mods (other ': accept) a :: Type) Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

data Param Source #

Constructors

PathParam PathParam 
HeaderParam HeaderParam 
QueryParam QP 
BodyEncoder 
Ignore

This is for things like Summary

Instances

Instances details
Eq Param Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

Methods

(==) :: Param -> Param -> Bool #

(/=) :: Param -> Param -> Bool #

data PathParam Source #

Constructors

Static Text 
Capture Text 

Instances

Instances details
Eq PathParam Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

data HeaderParam Source #

Instances

Instances details
Eq HeaderParam Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

data QP Source #

Instances

Instances details
Eq QP Source # 
Instance details

Defined in Data.JsonSpec.Elm.Servant

Methods

(==) :: QP -> QP -> Bool #

(/=) :: QP -> QP -> Bool #