add: configs as json GUC for db-root-spec

These are needed for a complete OpenAPI spec
This commit is contained in:
steve-chavez
2026-08-03 23:41:03 -05:00
committed by Steve Chavez
parent f84c44dafa
commit f34ca15e84
6 changed files with 94 additions and 32 deletions
+32 -3
View File
@@ -8,19 +8,29 @@ import Test.Hspec.Wai.JSON
import PostgREST.Config (AppConfig (..))
import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..))
import PostgREST.Version (prettyVersion)
import Protolude hiding (get)
import SpecHelper
spec :: SpecWithConfig
spec withConfig = withConfig (baseCfg { configDbRootSpec = Just $ QualifiedIdentifier mempty "root" }) $
spec withConfig = withConfig (baseCfg
{ configDbRootSpec = Just $ QualifiedIdentifier mempty "root"
, configDbSchemas = "test" :| ["v1"]
, configOpenApiServerProxyUri = Just "https://example.com/base"
}) $
describe "root spec function" $ do
it "accepts application/openapi+json" $ do
request methodGet "/"
[("Accept","application/openapi+json")] "" `shouldRespondWith`
[json|{
"swagger": "2.0",
"info": {"title": "PostgREST API", "description": "This is a dynamic API generated by PostgREST"}
"info": {"title": "PostgREST API", "description": "This is a dynamic API generated by PostgREST"},
"pgrst_server_host": "localhost",
"pgrst_server_port": "3000",
"pgrst_openapi_server_proxy_uri": "https://example.com/base",
"pgrst_db_schemas": ["test", "v1"],
"pgrst_version": #{decodeUtf8 prettyVersion}
}|]
{ matchHeaders = ["Content-Type" <:> "application/openapi+json; charset=utf-8"] }
@@ -29,6 +39,25 @@ spec withConfig = withConfig (baseCfg { configDbRootSpec = Just $ QualifiedIdent
[("Accept","application/json")] "" `shouldRespondWith`
[json|{
"swagger": "2.0",
"info": {"title": "PostgREST API", "description": "This is a dynamic API generated by PostgREST"}
"info": {"title": "PostgREST API", "description": "This is a dynamic API generated by PostgREST"},
"pgrst_server_host": "localhost",
"pgrst_server_port": "3000",
"pgrst_openapi_server_proxy_uri": "https://example.com/base",
"pgrst_db_schemas": ["test", "v1"],
"pgrst_version": #{decodeUtf8 prettyVersion}
}|]
{ matchHeaders = ["Content-Type" <:> "application/json; charset=utf-8"] }
it "returns null GUCs on non-root paths" $ do
request methodGet "/rpc/root"
[("Accept","application/openapi+json")] "" `shouldRespondWith`
[json|{
"swagger": "2.0",
"info": {"title": "PostgREST API", "description": "This is a dynamic API generated by PostgREST"},
"pgrst_server_host": null,
"pgrst_server_port": null,
"pgrst_openapi_server_proxy_uri": null,
"pgrst_db_schemas": null,
"pgrst_version": null
}|]
{ matchHeaders = ["Content-Type" <:> "application/openapi+json; charset=utf-8"] }