From 57ebf43e8526c0dfcf5996feda08ca9f13da2709 Mon Sep 17 00:00:00 2001 From: Nathan Bouscal Date: Fri, 9 Aug 2019 20:10:20 +0100 Subject: [PATCH] Allow select in OpenAPI for POST requests (#1375) If you use `return=representation`, `select` is useful in `POST` requests. It already works correctly, but is missing from the OpenAPI spec. --- src/PostgREST/OpenAPI.hs | 2 +- test/Feature/StructureSpec.hs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/PostgREST/OpenAPI.hs b/src/PostgREST/OpenAPI.hs index 55ecb0866..24fb1099e 100644 --- a/src/PostgREST/OpenAPI.hs +++ b/src/PostgREST/OpenAPI.hs @@ -218,7 +218,7 @@ makePathItem (t, cs, _) = ("/" ++ unpack tn, p $ tableInsertable t) ) ) postOp = tOp - & parameters .~ map ref ["body." <> tn, "preferReturn"] + & parameters .~ map ref ["body." <> tn, "select", "preferReturn"] & at 201 ?~ "Created" patchOp = tOp & parameters .~ map ref (rs <> ["body." <> tn, "preferReturn"]) diff --git a/test/Feature/StructureSpec.hs b/test/Feature/StructureSpec.hs index 8bd20a9b3..dbdd5bb93 100644 --- a/test/Feature/StructureSpec.hs +++ b/test/Feature/StructureSpec.hs @@ -45,6 +45,7 @@ spec = do childGetSummary = r ^? method "get" . key "summary" childGetDescription = r ^? method "get" . key "description" getParameters = r ^? method "get" . key "parameters" + postParameters = r ^? method "post" . key "parameters" postResponse = r ^? method "post" . key "responses" . key "201" . key "description" patchResponse = r ^? method "patch" . key "responses" . key "204" . key "description" deleteResponse = r ^? method "delete" . key "responses" . key "204" . key "description" @@ -79,6 +80,15 @@ spec = do ] |] + postParameters `shouldBe` Just + [aesonQQ| + [ + { "$ref": "#/parameters/body.child_entities" }, + { "$ref": "#/parameters/select" }, + { "$ref": "#/parameters/preferReturn" } + ] + |] + postResponse `shouldBe` Just "Created" patchResponse `shouldBe` Just "No Content"