Skip to content

Commit e7df9d1

Browse files
committed
break: db-root-spec default app/openapi+json media
BREAKING CHANGE Can be done later with custom media types
1 parent 0d16076 commit e7df9d1

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
8787
+ Can be replaced with custom media types
8888
- #1462, #1548, Removed `application/octet-stream`, `text/plain`, `text/xml` [builtin support for scalar results](https://postgrest.org/en/v11.1/references/api/resource_representation.html#scalar-function-response-format) - @steve-chavez
8989
+ Can be replaced with custom media types
90+
- #1462, #1548, Removed default `application/openapi+json` media type for [db-root-spec](https://postgrest.org/en/v11.1/references/configuration.html#db-root-spec) - @steve-chavez
9091

9192
## [11.1.0] - 2023-06-07
9293

src/PostgREST/ApiRequest.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module PostgREST.ApiRequest
1515
, Action(..)
1616
, Target(..)
1717
, Payload(..)
18-
, PathInfo(..)
1918
, userApiRequest
2019
) where
2120

@@ -127,7 +126,6 @@ data ApiRequest = ApiRequest {
127126
, iHeaders :: [(ByteString, ByteString)] -- ^ HTTP request headers
128127
, iCookies :: [(ByteString, ByteString)] -- ^ Request Cookies
129128
, iPath :: ByteString -- ^ Raw request path
130-
, iPathInfo :: PathInfo -- ^ Cached info about the path
131129
, iMethod :: ByteString -- ^ Raw request method
132130
, iSchema :: Schema -- ^ The request schema. Can vary depending on profile headers.
133131
, iNegotiatedByProfile :: Bool -- ^ If schema was was chosen according to the profile spec https://www.w3.org/TR/dx-prof-conneg/
@@ -158,7 +156,6 @@ userApiRequest conf req reqBody = do
158156
, iHeaders = iHdrs
159157
, iCookies = iCkies
160158
, iPath = rawPathInfo req
161-
, iPathInfo = pInfo
162159
, iMethod = method
163160
, iSchema = schema
164161
, iNegotiatedByProfile = negotiatedByProfile

src/PostgREST/Plan.hs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import PostgREST.ApiRequest (Action (..),
4141
ApiRequest (..),
4242
InvokeMethod (..),
4343
Mutation (..),
44-
PathInfo (..),
4544
Payload (..))
4645
import PostgREST.Config (AppConfig (..))
4746
import PostgREST.Error (Error (..))
@@ -123,15 +122,15 @@ data InspectPlan = InspectPlan {
123122
wrappedReadPlan :: QualifiedIdentifier -> AppConfig -> SchemaCache -> ApiRequest -> Either Error WrappedReadPlan
124123
wrappedReadPlan identifier conf sCache apiRequest@ApiRequest{iPreferences=Preferences{..},..} = do
125124
rPlan <- readPlan identifier conf sCache apiRequest
126-
mediaType <- mapLeft ApiRequestError $ negotiateContent conf iAction iPathInfo iAcceptMediaType
125+
mediaType <- mapLeft ApiRequestError $ negotiateContent conf iAction iAcceptMediaType
127126
if not (null invalidPrefs) && preferHandling == Just Strict then Left $ ApiRequestError $ InvalidPreferences invalidPrefs else Right ()
128127
return $ WrappedReadPlan rPlan SQL.Read (mediaToAggregate mediaType apiRequest) mediaType
129128

130129
mutateReadPlan :: Mutation -> ApiRequest -> QualifiedIdentifier -> AppConfig -> SchemaCache -> Either Error MutateReadPlan
131130
mutateReadPlan mutation apiRequest@ApiRequest{iPreferences=Preferences{..},..} identifier conf sCache = do
132131
rPlan <- readPlan identifier conf sCache apiRequest
133132
mPlan <- mutatePlan mutation identifier apiRequest sCache rPlan
134-
mediaType <- mapLeft ApiRequestError $ negotiateContent conf iAction iPathInfo iAcceptMediaType
133+
mediaType <- mapLeft ApiRequestError $ negotiateContent conf iAction iAcceptMediaType
135134
if not (null invalidPrefs) && preferHandling == Just Strict then Left $ ApiRequestError $ InvalidPreferences invalidPrefs else Right ()
136135
return $ MutateReadPlan rPlan mPlan SQL.Write (mediaToAggregate mediaType apiRequest) mediaType
137136

@@ -157,15 +156,15 @@ callReadPlan identifier conf sCache apiRequest@ApiRequest{iPreferences=Preferenc
157156
(InvPost, Routine.Immutable) -> SQL.Read
158157
(InvPost, Routine.Volatile) -> SQL.Write
159158
cPlan = callPlan proc apiRequest paramKeys args rPlan
160-
mediaType <- mapLeft ApiRequestError $ negotiateContent conf iAction iPathInfo iAcceptMediaType
159+
mediaType <- mapLeft ApiRequestError $ negotiateContent conf iAction iAcceptMediaType
161160
if not (null invalidPrefs) && preferHandling == Just Strict then Left $ ApiRequestError $ InvalidPreferences invalidPrefs else Right ()
162161
return $ CallReadPlan rPlan cPlan txMode proc (mediaToAggregate mediaType apiRequest) mediaType
163162
where
164163
qsParams' = QueryParams.qsParams iQueryParams
165164

166165
inspectPlan :: AppConfig -> ApiRequest -> Either Error InspectPlan
167166
inspectPlan conf apiRequest = do
168-
mediaType <- mapLeft ApiRequestError $ negotiateContent conf (iAction apiRequest) (iPathInfo apiRequest) (iAcceptMediaType apiRequest)
167+
mediaType <- mapLeft ApiRequestError $ negotiateContent conf (iAction apiRequest) (iAcceptMediaType apiRequest)
169168
return $ InspectPlan mediaType SQL.Read
170169

171170
{-|
@@ -851,29 +850,26 @@ mediaToAggregate mt apiReq@ApiRequest{iAction=act, iPreferences=Preferences{pref
851850
_ -> False
852851

853852
-- | Do content negotiation. i.e. choose a media type based on the intersection of accepted/produced media types.
854-
negotiateContent :: AppConfig -> Action -> PathInfo -> [MediaType] -> Either ApiRequestError MediaType
855-
negotiateContent conf action path accepts =
853+
negotiateContent :: AppConfig -> Action -> [MediaType] -> Either ApiRequestError MediaType
854+
negotiateContent conf action accepts =
856855
case firstAcceptedPick of
857856
Just MTAny -> Right MTApplicationJSON -- by default(for */*) we respond with json
858857
Just mt -> Right mt
859858
Nothing -> Left . MediaTypeError $ map MediaType.toMime accepts
860859
where
861860
-- if there are multiple accepted media types, pick the first
862-
firstAcceptedPick = listToMaybe $ L.intersect accepts $ producedMediaTypes conf action path
861+
firstAcceptedPick = listToMaybe $ L.intersect accepts $ producedMediaTypes conf action
863862

864-
producedMediaTypes :: AppConfig -> Action -> PathInfo -> [MediaType]
865-
producedMediaTypes conf action path =
863+
producedMediaTypes :: AppConfig -> Action -> [MediaType]
864+
producedMediaTypes conf action =
866865
case action of
867866
ActionRead _ -> defaultMediaTypes
868-
ActionInvoke _ -> invokeMediaTypes
867+
ActionInvoke _ -> defaultMediaTypes
869868
ActionInfo -> defaultMediaTypes
870869
ActionMutate _ -> defaultMediaTypes
871870
ActionInspect _ -> inspectMediaTypes
872871
where
873872
inspectMediaTypes = [MTOpenAPI, MTApplicationJSON, MTArrayJSONStrip, MTAny]
874-
invokeMediaTypes =
875-
defaultMediaTypes
876-
++ [MTOpenAPI | pathIsRootSpec path]
877873
defaultMediaTypes =
878874
[MTApplicationJSON, MTArrayJSONStrip, MTSingularJSON True, MTSingularJSON False, MTGeoJSON, MTTextCSV] ++
879875
[MTPlan MTApplicationJSON PlanText mempty | configDbPlanEnabled conf] ++ [MTAny]

test/spec/Feature/OpenApi/RootSpec.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Feature.OpenApi.RootSpec where
33
import Network.HTTP.Types
44
import Network.Wai (Application)
55

6-
import Test.Hspec
6+
import Test.Hspec hiding (pendingWith)
77
import Test.Hspec.Wai
88
import Test.Hspec.Wai.JSON
99

@@ -12,7 +12,8 @@ import Protolude hiding (get)
1212
spec :: SpecWith ((), Application)
1313
spec =
1414
describe "root spec function" $ do
15-
it "accepts application/openapi+json" $
15+
it "accepts application/openapi+json" $ do
16+
pendingWith "TBD"
1617
request methodGet "/"
1718
[("Accept","application/openapi+json")] "" `shouldRespondWith`
1819
[json|{

0 commit comments

Comments
 (0)