Close #1158, Add summary to OpenAPI doc for RPC functions (#1170)

This commit is contained in:
mdr1384
2018-08-27 10:22:21 -05:00
committed by Steve Chávez
parent 6907e7f979
commit dfa9055c34
4 changed files with 25 additions and 7 deletions
+1
View File
@@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #1145, Add materialized view columns to OpenAPI output - @steve-chavez
- #709, Allow embedding on views with subselects/CTE - @steve-chavez
- #1148, OpenAPI: add `required` section for the non-nullable columns - @laughedelic
- #1158, Add summary to OpenAPI doc for RPC functions - @mdr1384
### Fixed
+6 -1
View File
@@ -223,8 +223,13 @@ makePathItem (t, cs, _) = ("/" ++ unpack tn, p $ tableInsertable t)
makeProcPathItem :: ProcDescription -> (FilePath, PathItem)
makeProcPathItem pd = ("/rpc/" ++ toS (pdName pd), pe)
where
-- Use first line of proc description as summary; rest as description (if present)
-- We strip leading newlines from description so that users can include a blank line between summary and description
(pSum, pDesc) = fmap fst &&& fmap (dropWhile (=='\n') . snd) $
breakOn "\n" <$> pdDescription pd
postOp = (mempty :: Operation)
& description .~ pdDescription pd
& summary .~ pSum
& description .~ mfilter (/="") pDesc
& parameters .~ makeProcParam pd
& tags .~ Set.fromList ["(rpc) " <> pdName pd]
& produces ?~ makeMimeList [CTApplicationJSON, CTSingularJSON]
+14 -6
View File
@@ -221,13 +221,20 @@ spec = do
describe "RPC" $ do
it "includes body schema for arguments" $ do
it "includes function summary/description and body schema for arguments" $ do
r <- simpleBody <$> get "/"
let args = r ^? key "paths" . key "/rpc/varied_arguments"
. key "post" . key "parameters"
. nth 0 . key "schema"
liftIO $
let method s = key "paths" . key "/rpc/varied_arguments" . key s
args = r ^? method "post" . key "parameters" . nth 0 . key "schema"
summary = r ^? method "post" . key "summary"
description = r ^? method "post" . key "description"
liftIO $ do
summary `shouldBe` Just "An RPC function"
description `shouldBe` Just "Just a test for RPC function arguments"
args `shouldBe` Just
[aesonQQ|
{
@@ -269,7 +276,8 @@ spec = do
"type": "integer"
}
},
"type": "object"
"type": "object",
"description": "An RPC function\n\nJust a test for RPC function arguments"
}
|]
+4
View File
@@ -222,6 +222,10 @@ AS $_$
SELECT 'Hi'::text;
$_$;
COMMENT ON FUNCTION varied_arguments(double precision, character varying, boolean, date, money, enum_menagerie_type, integer) IS
$_$An RPC function
Just a test for RPC function arguments$_$;
--
-- Name: jwt_test(); Type: FUNCTION; Schema: test; Owner: -