fix: remove rejected mediatype application/vnd.pgrst.object+json from response

This commit is contained in:
Taimoor Zaeem
2024-05-09 18:56:47 +02:00
committed by Wolfgang Walther
parent 977710f442
commit 67f6b1c7e8
5 changed files with 35 additions and 22 deletions
+1
View File
@@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #3224, Return status code 406 for non-accepted media type instead of code 415 - @wolfgangwalther
- #3160, Fix using select= query parameter for custom media type handlers - @wolfgangwalther
- #3361, Clarify PGRST204(column not found) error message - @steve-chavez
- #3373, Remove rejected mediatype `application/vnd.pgrst.object+json` from response - @taimoorzaeem
## [12.0.2] - 2023-12-20
-1
View File
@@ -92,7 +92,6 @@ instance PgrstError ApiRequestError where
status SingularityError{} = HTTP.status406
status PGRSTParseError = HTTP.status500
headers SingularityError{} = [MediaType.toContentType $ MTVndSingularJSON False]
headers _ = mempty
toJsonPgrstError :: ErrorCode -> Text -> Maybe JSON.Value -> Maybe JSON.Value -> JSON.Value
+1 -1
View File
@@ -72,7 +72,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 6 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [matchContentTypeSingular]
, matchHeaders = [matchContentTypeJson]
}
context "strip nulls from response even if explicitly selected" $ do
+16 -16
View File
@@ -72,7 +72,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 4 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [ matchContentTypeSingular ]
, matchHeaders = [ matchContentTypeJson ]
}
-- the rows should not be updated, either
@@ -87,7 +87,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 4 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [ matchContentTypeSingular ]
, matchHeaders = [ matchContentTypeJson ]
}
-- the rows should not be updated, either
@@ -101,7 +101,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [matchContentTypeSingular]
, matchHeaders = [matchContentTypeJson]
}
it "raises an error for zero rows with return=rep" $
@@ -110,7 +110,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [matchContentTypeSingular]
, matchHeaders = [matchContentTypeJson]
}
context "when creating rows" $ do
@@ -143,7 +143,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 2 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [ matchContentTypeSingular ]
, matchHeaders = [ matchContentTypeJson ]
}
-- the rows should not exist, either
@@ -158,7 +158,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 2 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [ matchContentTypeSingular ]
, matchHeaders = [ matchContentTypeJson ]
}
-- the rows should not exist, either
@@ -173,7 +173,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 2 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [ matchContentTypeSingular ]
, matchHeaders = [ matchContentTypeJson ]
}
-- the rows should not exist, either
@@ -188,7 +188,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [matchContentTypeSingular]
, matchHeaders = [matchContentTypeJson]
}
it "raises an error when creating zero entities with return=rep" $
@@ -198,7 +198,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [matchContentTypeSingular]
, matchHeaders = [matchContentTypeJson]
}
context "when deleting rows" $ do
@@ -221,7 +221,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 5 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [ matchContentTypeSingular ]
, matchHeaders = [ matchContentTypeJson ]
}
-- the rows should still exist
@@ -238,7 +238,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 5 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [ matchContentTypeSingular ]
, matchHeaders = [ matchContentTypeJson ]
}
-- the rows should still exist
@@ -254,7 +254,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [matchContentTypeSingular]
, matchHeaders = [matchContentTypeJson]
}
it "raises an error when deleting zero entities with return=rep" $
@@ -263,7 +263,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [matchContentTypeSingular]
, matchHeaders = [matchContentTypeJson]
}
context "when calling a stored proc" $ do
@@ -273,7 +273,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 0 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [matchContentTypeSingular]
, matchHeaders = [matchContentTypeJson]
}
-- this one may be controversial, should vnd.pgrst.object include
@@ -296,7 +296,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 5 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [matchContentTypeSingular]
, matchHeaders = [matchContentTypeJson]
}
it "fails for multiple rows with rolled back changes" $ do
@@ -311,7 +311,7 @@ spec =
`shouldRespondWith`
[json|{"details":"The result contains 2 rows","message":"JSON object requested, multiple (or no) rows returned","code":"PGRST116","hint":null}|]
{ matchStatus = 406
, matchHeaders = [ matchContentTypeSingular]
, matchHeaders = [ matchContentTypeJson ]
}
-- should rollback function
+17 -4
View File
@@ -1,3 +1,4 @@
{-# LANGUAGE FlexibleContexts #-}
module SpecHelper where
import Control.Lens ((^?))
@@ -36,17 +37,29 @@ import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..))
import Protolude hiding (get, toS)
import Protolude.Conv (toS)
filterAndMatchCT :: BS.ByteString -> MatchHeader
filterAndMatchCT val = MatchHeader $ \headers _ ->
case filter (\(n,_) -> n == hContentType) headers of
[(_,v)] -> if v == val
then Nothing
else Just $ "missing value:" <> toS val <> "\n"
_ -> Just "unexpected header: zero or multiple headers present\n"
matchContentTypeJson :: MatchHeader
matchContentTypeJson = "Content-Type" <:> "application/json; charset=utf-8"
matchContentTypeJson =
filterAndMatchCT "application/json; charset=utf-8"
matchContentTypeSingular :: MatchHeader
matchContentTypeSingular = "Content-Type" <:> "application/vnd.pgrst.object+json; charset=utf-8"
matchContentTypeSingular =
filterAndMatchCT "application/vnd.pgrst.object+json; charset=utf-8"
matchCTArrayStrip :: MatchHeader
matchCTArrayStrip = "Content-Type" <:> "application/vnd.pgrst.array+json;nulls=stripped; charset=utf-8"
matchCTArrayStrip =
filterAndMatchCT "application/vnd.pgrst.array+json;nulls=stripped; charset=utf-8"
matchCTSingularStrip :: MatchHeader
matchCTSingularStrip = "Content-Type" <:> "application/vnd.pgrst.object+json;nulls=stripped; charset=utf-8"
matchCTSingularStrip =
filterAndMatchCT "application/vnd.pgrst.object+json;nulls=stripped; charset=utf-8"
matchHeaderValuePresent :: HeaderName -> BS.ByteString -> MatchHeader
matchHeaderValuePresent name val = MatchHeader $ \headers _ ->