From 15039553db960f4453230ce7b4dc23c86bb6c561 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Thu, 7 Jan 2021 17:18:05 -0500 Subject: [PATCH] Correct openapi preparing statements by default --- src/PostgREST/App.hs | 6 +++--- src/PostgREST/DbStructure.hs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs index c6766daec..ae62ebe6a 100644 --- a/src/PostgREST/App.hs +++ b/src/PostgREST/App.hs @@ -330,9 +330,9 @@ app dbStructure conf apiRequest = encodeApi ti sd procs = encodeOpenAPI (concat $ M.elems procs) (toTableInfo ti) uri' sd $ dbPrimaryKeys dbStructure body <- encodeApi <$> - H.statement tSchema accessibleTables <*> - H.statement tSchema schemaDescription <*> - H.statement tSchema accessibleProcs + H.statement tSchema (accessibleTables prepared) <*> + H.statement tSchema (schemaDescription prepared) <*> + H.statement tSchema (accessibleProcs prepared) return $ responseLBS status200 (catMaybes [Just $ toHeader CTOpenAPI, profileH]) (if headersOnly then mempty else toS body) _ -> return notFound diff --git a/src/PostgREST/DbStructure.hs b/src/PostgREST/DbStructure.hs index f2dff5693..1da433c75 100644 --- a/src/PostgREST/DbStructure.hs +++ b/src/PostgREST/DbStructure.hs @@ -172,8 +172,8 @@ allProcs = H.Statement (toS sql) (arrayParam HE.text) decodeProcs where sql = procsSqlQuery <> " WHERE pn.nspname = ANY($1)" -accessibleProcs :: H.Statement Schema ProcsMap -accessibleProcs = H.Statement (toS sql) (param HE.text) decodeProcs True +accessibleProcs :: Bool -> H.Statement Schema ProcsMap +accessibleProcs = H.Statement (toS sql) (param HE.text) decodeProcs where sql = procsSqlQuery <> " WHERE pn.nspname = $1 AND has_function_privilege(p.oid, 'execute')" @@ -244,9 +244,9 @@ procsSqlQuery = [q| LEFT JOIN pg_catalog.pg_description as d ON d.objoid = p.oid |] -schemaDescription :: H.Statement Schema (Maybe Text) +schemaDescription :: Bool -> H.Statement Schema (Maybe Text) schemaDescription = - H.Statement sql (param HE.text) (join <$> HD.rowMaybe (nullableColumn HD.text)) True + H.Statement sql (param HE.text) (join <$> HD.rowMaybe (nullableColumn HD.text)) where sql = [q| select @@ -257,9 +257,9 @@ schemaDescription = where n.nspname = $1 |] -accessibleTables :: H.Statement Schema [Table] +accessibleTables :: Bool -> H.Statement Schema [Table] accessibleTables = - H.Statement sql (param HE.text) decodeTables True + H.Statement sql (param HE.text) decodeTables where sql = [q| select