Include proc parama and their types in openapi

This commit is contained in:
Joe Nelson
2016-09-08 23:00:52 -07:00
parent f49c6aa0f3
commit b9777dec35
3 changed files with 33 additions and 6 deletions
+12 -3
View File
@@ -16,7 +16,7 @@ import Control.Applicative
import Data.List (elemIndex)
import Data.Maybe (fromJust)
import Data.Monoid
import Data.Text (split)
import Data.Text (split, strip)
import qualified Hasql.Session as H
import PostgREST.Types
import Text.InterpolatedString.Perl6 (q)
@@ -99,12 +99,21 @@ accessibleProcs :: H.Query Schema [(Text, ProcDescription)]
accessibleProcs =
H.statement sql (HE.value HE.text)
(map addName <$> HD.rowsList (ProcDescription <$> HD.value HD.text
<*> HD.value HD.text
<*> HD.value HD.text)) True
<*> (parseArgs <$> HD.value HD.text)
<*> HD.value HD.text)) True
where
addName :: ProcDescription -> (Text, ProcDescription)
addName pd = (pdName pd, pd)
parseArgs :: Text -> [(PgArgName, PgArgType)]
parseArgs = mapMaybe list2pair
. map (split (==' ') . strip)
. split (==',')
list2pair :: [a] -> Maybe (a,a)
list2pair (x:y:_) = Just (x,y)
list2pair _ = Nothing
sql = [q|
SELECT p.proname as "proc_name",
pg_get_function_arguments(p.oid) as "args",