Safe Haskell | None |
---|---|
Language | Haskell2010 |
Generalizes all the data needed to make code generation work with arbitrary programming languages.
- newtype FunctionName = FunctionName {
- unFunctionName :: [Text]
- _FunctionName :: Iso' FunctionName [Text]
- newtype PathSegment = PathSegment {}
- _PathSegment :: Iso' PathSegment Text
- data Arg f = Arg {
- _argName :: PathSegment
- _argType :: f
- argType :: forall f f. Lens (Arg f) (Arg f) f f
- argName :: forall f. Lens' (Arg f) PathSegment
- argPath :: Getter (Arg f) Text
- data SegmentType f
- = Static PathSegment
- | Cap (Arg f)
- _Cap :: forall f f. Prism (SegmentType f) (SegmentType f) (Arg f) (Arg f)
- _Static :: forall f. Prism' (SegmentType f) PathSegment
- newtype Segment f = Segment {
- unSegment :: SegmentType f
- _Segment :: forall f f. Iso (Segment f) (Segment f) (SegmentType f) (SegmentType f)
- isCapture :: Segment f -> Bool
- captureArg :: Segment f -> Arg f
- type Path f = [Segment f]
- data ArgType
- _List :: Prism' ArgType ()
- _Flag :: Prism' ArgType ()
- _Normal :: Prism' ArgType ()
- data QueryArg f = QueryArg {
- _queryArgName :: Arg f
- _queryArgType :: ArgType
- queryArgType :: forall f. Lens' (QueryArg f) ArgType
- queryArgName :: forall f f. Lens (QueryArg f) (QueryArg f) (Arg f) (Arg f)
- data HeaderArg f
- = HeaderArg {
- _headerArg :: Arg f
- | ReplaceHeaderArg {
- _headerArg :: Arg f
- _headerPattern :: Text
- = HeaderArg {
- headerPattern :: forall f. Traversal' (HeaderArg f) Text
- headerArg :: forall f f. Lens (HeaderArg f) (HeaderArg f) (Arg f) (Arg f)
- _ReplaceHeaderArg :: forall f. Prism' (HeaderArg f) (Arg f, Text)
- _HeaderArg :: forall f. Prism' (HeaderArg f) (Arg f)
- data Url f = Url {}
- defUrl :: Url f
- queryStr :: forall f. Lens' (Url f) [QueryArg f]
- path :: forall f. Lens' (Url f) (Path f)
- data Req f = Req {
- _reqUrl :: Url f
- _reqMethod :: Method
- _reqHeaders :: [HeaderArg f]
- _reqBody :: Maybe f
- _reqReturnType :: Maybe f
- _reqFuncName :: FunctionName
- reqUrl :: forall f. Lens' (Req f) (Url f)
- reqReturnType :: forall f. Lens' (Req f) (Maybe f)
- reqMethod :: forall f. Lens' (Req f) Method
- reqHeaders :: forall f. Lens' (Req f) [HeaderArg f]
- reqFuncName :: forall f. Lens' (Req f) FunctionName
- reqBody :: forall f. Lens' (Req f) (Maybe f)
- defReq :: Req ftype
- class HasForeignType lang ftype a where
- data NoTypes
- class HasForeign lang ftype api where
- data EmptyForeignAPI = EmptyForeignAPI
- class GenerateList ftype reqs where
- listFromAPI :: (HasForeign lang ftype api, GenerateList ftype (Foreign ftype api)) => Proxy lang -> Proxy ftype -> Proxy api -> [Req ftype]
Documentation
newtype FunctionName Source #
_FunctionName :: Iso' FunctionName [Text] Source #
newtype PathSegment Source #
Arg | |
|
data SegmentType f Source #
Static PathSegment | a static path segment. like "/foo" |
Cap (Arg f) | a capture. like "/:userid" |
Eq f => Eq (SegmentType f) Source # | |
Data f => Data (SegmentType f) Source # | |
Show f => Show (SegmentType f) Source # | |
_Cap :: forall f f. Prism (SegmentType f) (SegmentType f) (Arg f) (Arg f) Source #
_Static :: forall f. Prism' (SegmentType f) PathSegment Source #
Segment | |
|
_Segment :: forall f f. Iso (Segment f) (Segment f) (SegmentType f) (SegmentType f) Source #
captureArg :: Segment f -> Arg f Source #
QueryArg | |
|
HeaderArg | |
| |
ReplaceHeaderArg | |
|
headerPattern :: forall f. Traversal' (HeaderArg f) Text Source #
Req | |
|
reqFuncName :: forall f. Lens' (Req f) FunctionName Source #
class HasForeignType lang ftype a where Source #
HasForeignType
maps Haskell types with types in the target
language of your backend. For example, let's say you're
implementing a backend to some language X, and you want
a Text representation of each input/output type mentioned in the API:
-- First you need to create a dummy type to parametrize your -- instances. data LangX -- Otherwise you define instances for the types you need instance HasForeignType LangX Text Int where typeFor _ _ _ = "intX" -- Or for example in case of lists instance HasForeignType LangX Text a => HasForeignType LangX Text [a] where typeFor lang type _ = "listX of " <> typeFor lang ftype (Proxy :: Proxy a)
Finally to generate list of information about all the endpoints for an API you create a function of a form:
getEndpoints :: (HasForeign LangX Text api, GenerateList Text (Foreign Text api)) => Proxy api -> [Req Text] getEndpoints api = listFromAPI (Proxy :: Proxy LangX) (Proxy :: Proxy Text) api
-- If language __X__ is dynamically typed then you can use -- a predefined NoTypes parameter with the NoContent output type:
getEndpoints :: (HasForeign NoTypes NoContent api, GenerateList Text (Foreign NoContent api)) => Proxy api -> [Req NoContent] getEndpoints api = listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) api
class HasForeign lang ftype api where Source #
HasForeign k lang ftype Raw Source # | |
HasForeign k lang ftype EmptyAPI Source # | |
(HasForeign k lang ftype a, HasForeign k lang ftype b) => HasForeign k lang ftype ((:<|>) a b) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype (WithNamedContext name context api) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype ((:>) * * (Description desc) api) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype ((:>) * * (Summary desc) api) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype ((:>) * * HttpVersion api) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype ((:>) * * Vault api) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype ((:>) * * IsSecure api) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype ((:>) * * RemoteHost api) Source # | |
(KnownSymbol path, HasForeign k lang ftype api) => HasForeign k lang ftype ((:>) * Symbol path api) Source # | |
(Elem * JSON list, HasForeignType k k1 lang ftype a, HasForeign k1 lang ftype api) => HasForeign k1 lang ftype ((:>) * * (ReqBody k list a) api) Source # | |
(KnownSymbol sym, HasForeignType * k lang ftype Bool, HasForeign k lang ftype api) => HasForeign k lang ftype ((:>) * * (QueryFlag sym) api) Source # | |
(KnownSymbol sym, HasForeignType * k lang ftype [a], HasForeign k lang ftype api) => HasForeign k lang ftype ((:>) * * (QueryParams * sym a) api) Source # | |
(KnownSymbol sym, HasForeignType k k1 lang ftype a, HasForeign k1 lang ftype api) => HasForeign k1 lang ftype ((:>) * * (QueryParam k sym a) api) Source # | |
(KnownSymbol sym, HasForeignType * k lang ftype a, HasForeign k lang ftype api) => HasForeign k lang ftype ((:>) * * (Header sym a) api) Source # | |
(KnownSymbol sym, HasForeignType * k lang ftype [t], HasForeign k lang ftype sublayout) => HasForeign k lang ftype ((:>) * * (CaptureAll * sym t) sublayout) Source # | |
(KnownSymbol sym, HasForeignType k k1 lang ftype t, HasForeign k1 lang ftype api) => HasForeign k1 lang ftype ((:>) * * (Capture k sym t) api) Source # | |
(Elem * JSON list, HasForeignType k k2 lang ftype a, ReflectMethod k1 method) => HasForeign k2 lang ftype (Verb k k1 method status list a) Source # | |
class GenerateList ftype reqs where Source #
Utility class used by listFromAPI
which computes
the data needed to generate a function for each endpoint
and hands it all back in a list.
generateList :: reqs -> [Req ftype] Source #
GenerateList ftype EmptyForeignAPI Source # | |
GenerateList ftype (Req ftype) Source # | |
(GenerateList ftype start, GenerateList ftype rest) => GenerateList ftype ((:<|>) start rest) Source # | |
listFromAPI :: (HasForeign lang ftype api, GenerateList ftype (Foreign ftype api)) => Proxy lang -> Proxy ftype -> Proxy api -> [Req ftype] Source #
Generate the necessary data for codegen as a list, each Req
describing one endpoint from your API type.