feat: make db-root-spec stable (#2694)

This commit is contained in:
Steve Chavez
2023-03-01 12:23:19 -05:00
committed by GitHub
parent 8213c58452
commit 3e99995e6a
8 changed files with 13 additions and 58 deletions
-8
View File
@@ -9,8 +9,6 @@ import Test.Hspec.Wai.JSON
import Protolude hiding (get)
import SpecHelper
spec :: SpecWith ((), Application)
spec =
describe "root spec function" $ do
@@ -22,9 +20,3 @@ spec =
"info": {"title": "PostgREST API", "description": "This is a dynamic API generated by PostgREST"}
}|]
{ matchHeaders = ["Content-Type" <:> "application/openapi+json; charset=utf-8"] }
it "accepts application/json" $
request methodGet "/"
[("Accept", "application/json")] "" `shouldRespondWith`
200
{ matchHeaders = [matchContentTypeJson] }
-6
View File
@@ -1,6 +1,5 @@
module Main where
import qualified Data.Aeson as JSON
import qualified Hasql.Pool as P
import qualified Hasql.Transaction.Sessions as HT
@@ -14,7 +13,6 @@ import PostgREST.Config (AppConfig (..))
import PostgREST.Config.Database (queryPgVersion)
import PostgREST.SchemaCache (querySchemaCache)
import Protolude hiding (toList, toS)
import Protolude.Conv (toS)
import SpecHelper
import qualified PostgREST.AppState as AppState
@@ -82,8 +80,6 @@ main = do
appState <- AppState.initWithPool pool config
AppState.putPgVersion appState actualPgVersion
AppState.putSchemaCache appState (Just baseSchemaCache)
when (isJust $ configDbRootSpec config) $
AppState.putJsonDbS appState $ toS $ JSON.encode baseSchemaCache
return ((), postgrest config appState $ pure ())
-- For tests that run with a different SchemaCache(depends on configSchemas)
@@ -95,8 +91,6 @@ main = do
appState <- AppState.initWithPool pool config
AppState.putPgVersion appState actualPgVersion
AppState.putSchemaCache appState (Just customSchemaCache)
when (isJust $ configDbRootSpec config) $
AppState.putJsonDbS appState $ toS $ JSON.encode baseSchemaCache
return ((), postgrest config appState $ pure ())
let withApp = app testCfg
+1 -13
View File
@@ -1907,20 +1907,8 @@ openapi json = $$
}
}
$$;
accept text;
begin
accept = case when current_setting('server_version_num')::int >= 140000
then current_setting('request.headers', true)::json->>'accept'
else current_setting('request.header.accept', true)
end;
case accept
when 'application/openapi+json' then
return openapi;
when 'application/json' then
return (current_setting('request.spec', true)::json)->'dbRelationships'->0->0;
else
return openapi;
end case;
return openapi;
end
$_$ language plpgsql;