Note which rpc params are optional
This commit is contained in:
@@ -105,14 +105,15 @@ accessibleProcs =
|
|||||||
addName :: ProcDescription -> (Text, ProcDescription)
|
addName :: ProcDescription -> (Text, ProcDescription)
|
||||||
addName pd = (pdName pd, pd)
|
addName pd = (pdName pd, pd)
|
||||||
|
|
||||||
parseArgs :: Text -> [(PgArgName, PgArgType)]
|
parseArgs :: Text -> [PgArg]
|
||||||
parseArgs = mapMaybe list2pair
|
parseArgs = mapMaybe toks2arg
|
||||||
. map (split (==' ') . strip)
|
. map (split (==' ') . strip)
|
||||||
. split (==',')
|
. split (==',')
|
||||||
|
|
||||||
list2pair :: [a] -> Maybe (a,a)
|
toks2arg :: [Text] -> Maybe PgArg
|
||||||
list2pair (x:y:_) = Just (x,y)
|
toks2arg (x:y:"DEFAULT":_) = Just (PgArg x y False)
|
||||||
list2pair _ = Nothing
|
toks2arg (x:y:_) = Just (PgArg x y True)
|
||||||
|
toks2arg _ = Nothing
|
||||||
|
|
||||||
sql = [q|
|
sql = [q|
|
||||||
SELECT p.proname as "proc_name",
|
SELECT p.proname as "proc_name",
|
||||||
|
|||||||
@@ -23,9 +23,8 @@ import Data.Swagger
|
|||||||
import PostgREST.ApiRequest (ContentType(..), toHeader)
|
import PostgREST.ApiRequest (ContentType(..), toHeader)
|
||||||
import PostgREST.Config (prettyVersion)
|
import PostgREST.Config (prettyVersion)
|
||||||
import PostgREST.QueryBuilder (operators)
|
import PostgREST.QueryBuilder (operators)
|
||||||
import PostgREST.Types (Table(..), Column(..),
|
import PostgREST.Types (Table(..), Column(..), PgArg(..),
|
||||||
Proxy(..), ProcDescription(..),
|
Proxy(..), ProcDescription(..))
|
||||||
PgArgName, PgArgType)
|
|
||||||
|
|
||||||
makeMimeList :: [ContentType] -> MimeList
|
makeMimeList :: [ContentType] -> MimeList
|
||||||
makeMimeList cs = MimeList $ map (fromString . toS . toHeader) cs
|
makeMimeList cs = MimeList $ map (fromString . toS . toHeader) cs
|
||||||
@@ -55,13 +54,15 @@ makeProperty c = (colName c, Inline u)
|
|||||||
u = t & format ?~ colType c
|
u = t & format ?~ colType c
|
||||||
|
|
||||||
makeProcDef :: ProcDescription -> (Text, Schema)
|
makeProcDef :: ProcDescription -> (Text, Schema)
|
||||||
makeProcDef pd =
|
makeProcDef pd = ("(rpc) " <> pdName pd, s)
|
||||||
("(rpc) " <> pdName pd, (mempty :: Schema)
|
where
|
||||||
& type_ .~ SwaggerObject
|
s = (mempty :: Schema)
|
||||||
& properties .~ (fromList $ map makeProcProperty (pdArgs pd)))
|
& type_ .~ SwaggerObject
|
||||||
|
& properties .~ (fromList $ map makeProcProperty (pdArgs pd))
|
||||||
|
& required .~ (map pgaName $ filter pgaReq (pdArgs pd))
|
||||||
|
|
||||||
makeProcProperty :: (PgArgName, PgArgType) -> (Text, Referenced Schema)
|
makeProcProperty :: PgArg -> (Text, Referenced Schema)
|
||||||
makeProcProperty (n, t) = (n, Inline s)
|
makeProcProperty (PgArg n t _) = (n, Inline s)
|
||||||
where
|
where
|
||||||
s = (mempty :: Schema)
|
s = (mempty :: Schema)
|
||||||
& type_ .~ toSwaggerType t
|
& type_ .~ toSwaggerType t
|
||||||
|
|||||||
@@ -16,12 +16,15 @@ data DbStructure = DbStructure {
|
|||||||
, dbProcs :: [(Text,ProcDescription)]
|
, dbProcs :: [(Text,ProcDescription)]
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
type PgArgName = Text
|
data PgArg = PgArg {
|
||||||
type PgArgType = Text
|
pgaName :: Text
|
||||||
|
, pgaType :: Text
|
||||||
|
, pgaReq :: Bool
|
||||||
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
data ProcDescription = ProcDescription {
|
data ProcDescription = ProcDescription {
|
||||||
pdName :: Text
|
pdName :: Text
|
||||||
, pdArgs :: [(PgArgName, PgArgType)]
|
, pdArgs :: [PgArg]
|
||||||
, pdReturnType :: Text
|
, pdReturnType :: Text
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user