From 9065ed65faf834f2c28aff5bfedd6e92b0c0d84b Mon Sep 17 00:00:00 2001 From: AnthonyFisi <55923180+AnthonyFisi@users.noreply.github.com> Date: Sat, 21 Jan 2023 19:34:55 -0500 Subject: [PATCH] feat: customizable OpenAPI title --- CHANGELOG.md | 1 + src/PostgREST/Response/OpenAPI.hs | 7 ++++--- test/spec/Feature/OpenApi/OpenApiSpec.hs | 14 ++++++++++++++ test/spec/fixtures/schema.sql | 6 ++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12290bb8c2..7949575b84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). + Offers a more flexible replacement for `!inner`, e.g. `/projects?select=*,clients(*)&clients=not.is.null` + Allows doing an anti join, e.g. `/projects?select=*,clients(*)&clients=is.null` + Allows using or across related tables conditions + - #1100, Customizable OpenAPI title - @AnthonyFisi ### Fixed diff --git a/src/PostgREST/Response/OpenAPI.hs b/src/PostgREST/Response/OpenAPI.hs index 3420a690f1..379599b905 100644 --- a/src/PostgREST/Response/OpenAPI.hs +++ b/src/PostgREST/Response/OpenAPI.hs @@ -359,8 +359,8 @@ postgrestSpec rels pds ti (s, h, p, b) sd allowSecurityDef = (mempty :: Swagger) & schemes ?~ [s'] & info .~ ((mempty :: Info) & version .~ T.decodeUtf8 prettyVersion - & title .~ "PostgREST API" - & description ?~ d) + & title .~ fromMaybe "PostgREST API" dTitle + & description ?~ fromMaybe "This is a dynamic API generated by PostgREST" dDesc) & externalDocs ?~ ((mempty :: ExternalDocs) & description ?~ "PostgREST Documentation" & url .~ URL ("https://postgrest.org/en/" <> docsVersion <> "/api.html")) @@ -375,8 +375,9 @@ postgrestSpec rels pds ti (s, h, p, b) sd allowSecurityDef = (mempty :: Swagger) where s' = if s == "http" then Http else Https h' = Just $ Host (T.unpack $ escapeHostName h) (Just (fromInteger p)) - d = fromMaybe "This is a dynamic API generated by PostgREST" sd securityDefName = "JWT" + (dTitle, dDesc) = fmap fst &&& fmap (T.dropWhile (=='\n') . snd) $ + T.breakOn "\n" <$> sd pickProxy :: Maybe Text -> Maybe Proxy pickProxy proxy diff --git a/test/spec/Feature/OpenApi/OpenApiSpec.hs b/test/spec/Feature/OpenApi/OpenApiSpec.hs index 761ce6d481..6e9e0f3656 100644 --- a/test/spec/Feature/OpenApi/OpenApiSpec.hs +++ b/test/spec/Feature/OpenApi/OpenApiSpec.hs @@ -42,6 +42,20 @@ spec actualPgVersion = describe "OpenAPI" $ do liftIO $ docsUrl `shouldBe` Just (String ("https://postgrest.org/en/" <> docsVersion <> "/api.html")) + describe "schema" $ do + + it "includes title and comments to schema" $ do + r <- simpleBody <$> get "/" + + let childGetTitle = r ^? key "info" . key "title" + let childGetDescription = r ^? key "info" . key "description" + + liftIO $ do + + childGetTitle `shouldBe` Just "My API title" + + childGetDescription `shouldBe` Just "My API description\nthat spans\nmultiple lines" + describe "table" $ do it "includes paths to tables" $ do diff --git a/test/spec/fixtures/schema.sql b/test/spec/fixtures/schema.sql index 4f9235f71e..7935ef7c66 100644 --- a/test/spec/fixtures/schema.sql +++ b/test/spec/fixtures/schema.sql @@ -26,6 +26,12 @@ CREATE SCHEMA "EXTRA ""@/\#~_-"; COMMENT ON SCHEMA v1 IS 'v1 schema'; COMMENT ON SCHEMA v2 IS 'v2 schema'; +COMMENT ON SCHEMA test IS +$$My API title + +My API description +that spans +multiple lines$$; -- -- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - --