Fix bad OpenAPI output when having functions with OUT/INOUT params
This commit is contained in:
committed by
Steve Chávez
parent
e1cab584a3
commit
7a3f350f1c
@@ -19,7 +19,7 @@ import qualified Data.HashMap.Strict as M
|
|||||||
import Data.List (elemIndex)
|
import Data.List (elemIndex)
|
||||||
import Data.Maybe (fromJust)
|
import Data.Maybe (fromJust)
|
||||||
import Data.Text (split, strip,
|
import Data.Text (split, strip,
|
||||||
breakOn, dropAround)
|
breakOn, dropAround, splitOn)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Hasql.Session as H
|
import qualified Hasql.Session as H
|
||||||
import PostgREST.Types
|
import PostgREST.Types
|
||||||
@@ -120,11 +120,12 @@ decodeProcs =
|
|||||||
addName pd = (pdName pd, pd)
|
addName pd = (pdName pd, pd)
|
||||||
|
|
||||||
parseArgs :: Text -> [PgArg]
|
parseArgs :: Text -> [PgArg]
|
||||||
parseArgs = mapMaybe (parseArg . strip) . split (==',')
|
parseArgs = mapMaybe parseArg . filter (not . isPrefixOf "OUT" . toS) . map strip . split (==',')
|
||||||
|
|
||||||
parseArg :: Text -> Maybe PgArg
|
parseArg :: Text -> Maybe PgArg
|
||||||
parseArg a =
|
parseArg a =
|
||||||
let (body, def) = breakOn " DEFAULT " a
|
let arg = lastDef "" $ splitOn "INOUT " a
|
||||||
|
(body, def) = breakOn " DEFAULT " arg
|
||||||
(name, typ) = breakOn " " body in
|
(name, typ) = breakOn " " body in
|
||||||
if T.null typ
|
if T.null typ
|
||||||
then Nothing
|
then Nothing
|
||||||
|
|||||||
@@ -200,6 +200,22 @@ spec = do
|
|||||||
|
|
||||||
liftIO $ funcTag `shouldBe` Just [aesonQQ|"(rpc) privileged_hello"|]
|
liftIO $ funcTag `shouldBe` Just [aesonQQ|"(rpc) privileged_hello"|]
|
||||||
|
|
||||||
|
it "doesn't include OUT params of function as required parameters" $ do
|
||||||
|
r <- simpleBody <$> get "/"
|
||||||
|
let params = r ^? key "paths" . key "/rpc/many_out_params"
|
||||||
|
. key "post" . key "parameters" . nth 0
|
||||||
|
. key "schema". key "required"
|
||||||
|
|
||||||
|
liftIO $ params `shouldBe` Nothing
|
||||||
|
|
||||||
|
it "includes INOUT params(with no DEFAULT) of function as required parameters" $ do
|
||||||
|
r <- simpleBody <$> get "/"
|
||||||
|
let params = r ^? key "paths" . key "/rpc/many_inout_params"
|
||||||
|
. key "post" . key "parameters" . nth 0
|
||||||
|
. key "schema". key "required"
|
||||||
|
|
||||||
|
liftIO $ params `shouldBe` Just [aesonQQ|["num", "str"]|]
|
||||||
|
|
||||||
describe "Allow header" $ do
|
describe "Allow header" $ do
|
||||||
|
|
||||||
it "includes read/write verbs for writeable table" $ do
|
it "includes read/write verbs for writeable table" $ do
|
||||||
|
|||||||
Vendored
+8
@@ -1272,6 +1272,14 @@ create table test.being_part (
|
|||||||
being int not null references test.being(being),
|
being int not null references test.being(being),
|
||||||
part int not null references test.part(part)
|
part int not null references test.part(part)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
create function test.many_out_params(OUT my_json pg_catalog.json, OUT num int, OUT str text) AS $$
|
||||||
|
select '{"a": 1, "b": "two"}'::json, 3, 'four'::text;
|
||||||
|
$$ language sql;
|
||||||
|
|
||||||
|
create function test.many_inout_params(INOUT num int, INOUT str text, INOUT b bool DEFAULT true) AS $$
|
||||||
|
select num, str, b;
|
||||||
|
$$ language sql;
|
||||||
--
|
--
|
||||||
-- PostgreSQL database dump complete
|
-- PostgreSQL database dump complete
|
||||||
--
|
--
|
||||||
|
|||||||
Reference in New Issue
Block a user