{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Data.API.Doc.Types
( URL
, HTTPMethod
, StatusCode
, Call(..)
, Header(..)
, Param(..)
, View(..)
, Sample(..)
, Body(..)
, DocInfo(..)
, renderAPIType
, renderBodyType
, mk_link
) where
import Data.API.PP
import Data.API.Types
import qualified Data.Text as T
import Text.Printf
type URL = String
type HTTPMethod = String
type StatusCode = Int
data Call
= Call
{ Call -> URL
call_http_method :: HTTPMethod
, Call -> [URL]
call_path :: [String]
, Call -> URL
call_description :: String
, Call -> Bool
call_auth_required :: Bool
, :: [Header]
, Call -> Maybe (APIType, URL)
call_body :: Maybe (APIType, String)
, Call -> [Param]
call_params :: [Param]
, Call -> [View]
call_views :: [View]
, Call -> [Sample]
call_samples :: [Sample]
}
deriving (Int -> Call -> URL -> URL
[Call] -> URL -> URL
Call -> URL
forall a.
(Int -> a -> URL -> URL)
-> (a -> URL) -> ([a] -> URL -> URL) -> Show a
showList :: [Call] -> URL -> URL
$cshowList :: [Call] -> URL -> URL
show :: Call -> URL
$cshow :: Call -> URL
showsPrec :: Int -> Call -> URL -> URL
$cshowsPrec :: Int -> Call -> URL -> URL
Show)
data
=
{ :: String
, :: String
, :: String
, :: APIType
, :: Bool
} deriving (Int -> Header -> URL -> URL
[Header] -> URL -> URL
Header -> URL
forall a.
(Int -> a -> URL -> URL)
-> (a -> URL) -> ([a] -> URL -> URL) -> Show a
showList :: [Header] -> URL -> URL
$cshowList :: [Header] -> URL -> URL
show :: Header -> URL
$cshow :: Header -> URL
showsPrec :: Int -> Header -> URL -> URL
$cshowsPrec :: Int -> Header -> URL -> URL
Show)
data Param
= Param
{ Param -> URL
param_name :: String
, Param -> URL
param_expl :: String
, Param -> URL
param_desc :: String
, Param -> Either URL APIType
param_type :: Either String APIType
, Param -> Bool
param_required :: Bool
} deriving (Int -> Param -> URL -> URL
[Param] -> URL -> URL
Param -> URL
forall a.
(Int -> a -> URL -> URL)
-> (a -> URL) -> ([a] -> URL -> URL) -> Show a
showList :: [Param] -> URL -> URL
$cshowList :: [Param] -> URL -> URL
show :: Param -> URL
$cshow :: Param -> URL
showsPrec :: Int -> Param -> URL -> URL
$cshowsPrec :: Int -> Param -> URL -> URL
Show)
data View
= View
{ View -> URL
view_id :: String
, View -> APIType
view_type :: APIType
, View -> URL
view_doc :: String
, View -> [Param]
view_params :: [Param]
} deriving (Int -> View -> URL -> URL
[View] -> URL -> URL
View -> URL
forall a.
(Int -> a -> URL -> URL)
-> (a -> URL) -> ([a] -> URL -> URL) -> Show a
showList :: [View] -> URL -> URL
$cshowList :: [View] -> URL -> URL
show :: View -> URL
$cshow :: View -> URL
showsPrec :: Int -> View -> URL -> URL
$cshowsPrec :: Int -> View -> URL -> URL
Show)
data Sample
= Sample
{ Sample -> Int
sample_status :: StatusCode
, Sample -> Body APIType
sample_type :: Body APIType
, Sample -> Maybe URL
sample_response :: Maybe String
} deriving (Int -> Sample -> URL -> URL
[Sample] -> URL -> URL
Sample -> URL
forall a.
(Int -> a -> URL -> URL)
-> (a -> URL) -> ([a] -> URL -> URL) -> Show a
showList :: [Sample] -> URL -> URL
$cshowList :: [Sample] -> URL -> URL
show :: Sample -> URL
$cshow :: Sample -> URL
showsPrec :: Int -> Sample -> URL -> URL
$cshowsPrec :: Int -> Sample -> URL -> URL
Show)
data Body t = EmptyBody
| JSONBody t
| OtherBody String
deriving (forall a b. a -> Body b -> Body a
forall a b. (a -> b) -> Body a -> Body b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Body b -> Body a
$c<$ :: forall a b. a -> Body b -> Body a
fmap :: forall a b. (a -> b) -> Body a -> Body b
$cfmap :: forall a b. (a -> b) -> Body a -> Body b
Functor, Int -> Body t -> URL -> URL
forall t. Show t => Int -> Body t -> URL -> URL
forall t. Show t => [Body t] -> URL -> URL
forall t. Show t => Body t -> URL
forall a.
(Int -> a -> URL -> URL)
-> (a -> URL) -> ([a] -> URL -> URL) -> Show a
showList :: [Body t] -> URL -> URL
$cshowList :: forall t. Show t => [Body t] -> URL -> URL
show :: Body t -> URL
$cshow :: forall t. Show t => Body t -> URL
showsPrec :: Int -> Body t -> URL -> URL
$cshowsPrec :: forall t. Show t => Int -> Body t -> URL -> URL
Show)
data DocInfo
= DocInfo
{ DocInfo -> URL -> [URL] -> URL
doc_info_call_url :: HTTPMethod -> [String] -> URL
, DocInfo -> TypeName -> URL
doc_info_type_url :: TypeName -> URL
}
renderBodyType :: DocInfo -> Body APIType -> String
renderBodyType :: DocInfo -> Body APIType -> URL
renderBodyType DocInfo
_ Body APIType
EmptyBody = URL
"empty"
renderBodyType DocInfo
di (JSONBody APIType
ty) = URL
"json " forall a. [a] -> [a] -> [a]
++ DocInfo -> APIType -> URL
renderAPIType DocInfo
di APIType
ty
renderBodyType DocInfo
_ (OtherBody URL
s) = URL
s
renderAPIType :: DocInfo -> APIType -> String
renderAPIType :: DocInfo -> APIType -> URL
renderAPIType DocInfo
di (TyList APIType
ty ) = URL
"[" forall a. [a] -> [a] -> [a]
++ DocInfo -> APIType -> URL
renderAPIType DocInfo
di APIType
ty forall a. [a] -> [a] -> [a]
++ URL
"]"
renderAPIType DocInfo
di (TyMaybe APIType
ty ) = URL
"?" forall a. [a] -> [a] -> [a]
++ DocInfo -> APIType -> URL
renderAPIType DocInfo
di APIType
ty
renderAPIType DocInfo
di (TyName TypeName
tn ) = URL -> URL -> URL
mk_link (DocInfo -> TypeName -> URL
doc_info_type_url DocInfo
di TypeName
tn) (Text -> URL
T.unpack (TypeName -> Text
_TypeName TypeName
tn))
renderAPIType DocInfo
_ (TyBasic BasicType
bt ) = forall t. PP t => t -> URL
pp BasicType
bt
renderAPIType DocInfo
_ APIType
TyJSON = URL
"json"
mk_link :: URL -> String -> String
mk_link :: URL -> URL -> URL
mk_link = forall r. PrintfType r => URL -> r
printf URL
"<b><a class='reflink' href='%s' >%s</a></b>"