Expose stored proc args properly as json body param
This commit is contained in:
+26
-27
@@ -37,6 +37,13 @@ toSwaggerType "boolean" = SwaggerBoolean
|
||||
toSwaggerType "numeric" = SwaggerNumber
|
||||
toSwaggerType _ = SwaggerString
|
||||
|
||||
makeTableDef :: (Table, [Column], [Text]) -> (Text, Schema)
|
||||
makeTableDef (t, cs, _) =
|
||||
let tn = tableName t in
|
||||
(tn, (mempty :: Schema)
|
||||
& type_ .~ SwaggerObject
|
||||
& properties .~ (fromList $ map makeProperty cs))
|
||||
|
||||
makeProperty :: Column -> (Text, Referenced Schema)
|
||||
makeProperty c = (colName c, Inline u)
|
||||
where
|
||||
@@ -47,18 +54,18 @@ makeProperty c = (colName c, Inline u)
|
||||
t = s & type_ .~ toSwaggerType (colType c)
|
||||
u = t & format ?~ colType c
|
||||
|
||||
makeProperties :: [Column] -> InsOrdHashMap Text (Referenced Schema)
|
||||
makeProperties cs = fromList $ map makeProperty cs
|
||||
makeProcDef :: ProcDescription -> (Text, Schema)
|
||||
makeProcDef pd =
|
||||
("(rpc) " <> pdName pd, (mempty :: Schema)
|
||||
& type_ .~ SwaggerObject
|
||||
& properties .~ (fromList $ map makeProcProperty (pdArgs pd)))
|
||||
|
||||
makeDefinition :: (Table, [Column], [Text]) -> (Text, Schema)
|
||||
makeDefinition (t, cs, _) =
|
||||
let tn = tableName t in
|
||||
(tn, (mempty :: Schema)
|
||||
& type_ .~ SwaggerObject
|
||||
& properties .~ makeProperties cs)
|
||||
|
||||
makeDefinitions :: [(Table, [Column], [Text])] -> InsOrdHashMap Text Schema
|
||||
makeDefinitions ti = fromList $ map makeDefinition ti
|
||||
makeProcProperty :: (PgArgName, PgArgType) -> (Text, Referenced Schema)
|
||||
makeProcProperty (n, t) = (n, Inline s)
|
||||
where
|
||||
s = (mempty :: Schema)
|
||||
& type_ .~ toSwaggerType t
|
||||
& format ?~ t
|
||||
|
||||
makeOperatorPattern :: Text
|
||||
makeOperatorPattern =
|
||||
@@ -174,19 +181,12 @@ makePostParams tn =
|
||||
& schema .~ ParamBody (Ref (Reference tn))
|
||||
]
|
||||
|
||||
makeProcParams :: ProcDescription -> [Param]
|
||||
makeProcParams pd =
|
||||
map (makeProcParam $ pdName pd) (pdArgs pd)
|
||||
|
||||
makeProcParam :: Text -> (PgArgName, PgArgType) -> Param
|
||||
makeProcParam refName (n, t) =
|
||||
makeProcParam :: Text -> Param
|
||||
makeProcParam refName =
|
||||
(mempty :: Param)
|
||||
& name .~ n
|
||||
& required ?~ True
|
||||
-- & schema .~ ParamBody ((Ref (Reference refName))
|
||||
& schema .~ ParamOther ((mempty :: ParamOtherSchema)
|
||||
-- & in_ .~ ParamQuery
|
||||
& type_ .~ toSwaggerType t)
|
||||
& name .~ "args"
|
||||
& required ?~ True
|
||||
& schema .~ ParamBody (Ref (Reference refName))
|
||||
|
||||
makeDeleteParams :: [Param]
|
||||
makeDeleteParams =
|
||||
@@ -223,13 +223,12 @@ makeProcPathItem :: ProcDescription -> (FilePath, PathItem)
|
||||
makeProcPathItem pd = ("/rpc/" ++ toS (pdName pd), pe)
|
||||
where
|
||||
postOp = (mempty :: Operation)
|
||||
& parameters .~ map Inline (makeProcParams pd)
|
||||
& tags .~ Set.fromList ["/rpc/" <> pdName pd]
|
||||
& parameters .~ [Inline (makeProcParam $ "(rpc) " <> pdName pd)]
|
||||
& tags .~ Set.fromList ["(rpc) " <> pdName pd]
|
||||
& produces ?~ makeMimeList [CTApplicationJSON]
|
||||
& at 200 ?~ "OK"
|
||||
pe = (mempty :: PathItem) & post ?~ postOp
|
||||
|
||||
|
||||
makeRootPathItem :: (FilePath, PathItem)
|
||||
makeRootPathItem = ("/", p)
|
||||
where
|
||||
@@ -261,7 +260,7 @@ postgrestSpec pds ti (s, h, p, b) = (mempty :: Swagger)
|
||||
& title .~ "PostgREST API"
|
||||
& description ?~ "This is a dynamic API generated by PostgREST")
|
||||
& host .~ h'
|
||||
& definitions .~ makeDefinitions ti
|
||||
& definitions .~ (fromList $ map makeTableDef ti <> map makeProcDef pds)
|
||||
& paths .~ makePathItems pds ti
|
||||
where
|
||||
s' = if s == "http" then Http else Https
|
||||
|
||||
Reference in New Issue
Block a user