json-api 0.1.3.0 → 0.1.4.0
raw patch · 6 files changed
+73/−2 lines, 6 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Network.JSONApi: Source :: Maybe Text -> Maybe Text -> Source
+ Network.JSONApi: [parameter] :: Source -> Maybe Text
+ Network.JSONApi: [pointer] :: Source -> Maybe Text
+ Network.JSONApi: [source] :: Error a -> Maybe Source
+ Network.JSONApi: data Source
+ Network.JSONApi.Error: [source] :: Error a -> Maybe Source
+ Network.JSONApi.Source: Source :: Maybe Text -> Maybe Text -> Source
+ Network.JSONApi.Source: [parameter] :: Source -> Maybe Text
+ Network.JSONApi.Source: [pointer] :: Source -> Maybe Text
+ Network.JSONApi.Source: data Source
+ Network.JSONApi.Source: instance Data.Aeson.Types.FromJSON.FromJSON Network.JSONApi.Source.Source
+ Network.JSONApi.Source: instance Data.Aeson.Types.ToJSON.ToJSON Network.JSONApi.Source.Source
+ Network.JSONApi.Source: instance Data.Default.Class.Default Network.JSONApi.Source.Source
+ Network.JSONApi.Source: instance GHC.Classes.Eq Network.JSONApi.Source.Source
+ Network.JSONApi.Source: instance GHC.Generics.Generic Network.JSONApi.Source.Source
+ Network.JSONApi.Source: instance GHC.Show.Show Network.JSONApi.Source.Source
- Network.JSONApi: Error :: Maybe Text -> Maybe Links -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Meta -> Error a
+ Network.JSONApi: Error :: Maybe Text -> Maybe Links -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Source -> Maybe Meta -> Error a
- Network.JSONApi.Error: Error :: Maybe Text -> Maybe Links -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Meta -> Error a
+ Network.JSONApi.Error: Error :: Maybe Text -> Maybe Links -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Source -> Maybe Meta -> Error a
Files
- json-api.cabal +4/−2
- src/Network/JSONApi.hs +2/−0
- src/Network/JSONApi/Error.hs +3/−0
- src/Network/JSONApi/Source.hs +29/−0
- test/Network/JSONApi/ErrorSpec.hs +1/−0
- test/Network/JSONApi/SourceSpec.hs +34/−0
json-api.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 85cd43545d985dbf21e9ce90c112c8efc0c8553f194f84544f71d465a6a3a101+-- hash: 8976c29f6aaf0752e3accb80f6d7f3ac432f94e1d8df9092d2f0cb9beaad86d5 name: json-api-version: 0.1.3.0+version: 0.1.4.0 synopsis: Utilities for generating JSON-API payloads description: Provides utilities for deriving JSON payloads conformant to the json-api specification category: Network@@ -46,6 +46,7 @@ Network.JSONApi.Link Network.JSONApi.Resource Network.JSONApi.Pagination+ Network.JSONApi.Source other-modules: Paths_json_api hs-source-dirs:@@ -74,6 +75,7 @@ Network.JSONApi.MetaSpec Network.JSONApi.PaginationSpec Network.JSONApi.ResourceSpec+ Network.JSONApi.SourceSpec TestHelpers Paths_json_api hs-source-dirs:
src/Network/JSONApi.hs view
@@ -22,6 +22,7 @@ , P.PageSize (..) , P.ResourceCount (..) , P.Strategy (..)+, S.Source (..) , P.mkPaginationLinks , R.mkRelationship , R.mkRelationships@@ -42,4 +43,5 @@ import qualified Network.JSONApi.Meta as M import qualified Network.JSONApi.Pagination as P import qualified Network.JSONApi.Resource as R+import qualified Network.JSONApi.Source as S
src/Network/JSONApi/Error.hs view
@@ -16,6 +16,7 @@ import qualified GHC.Generics as G import Network.JSONApi.Link (Links) import Network.JSONApi.Meta+import Network.JSONApi.Source (Source) import Prelude hiding (id) {- |@@ -31,6 +32,7 @@ , code :: Maybe Text , title :: Maybe Text , detail :: Maybe Text+ , source :: Maybe Source , meta :: Maybe Meta } deriving (Show, Eq, G.Generic)@@ -46,5 +48,6 @@ , code = Nothing , title = Nothing , detail = Nothing+ , source = Nothing , meta = Nothing }
+ src/Network/JSONApi/Source.hs view
@@ -0,0 +1,29 @@+{- |+Module representing a JSON-API Source object.++Specification: <https://jsonapi.org/format/#error-objects>+ <https://tools.ietf.org/html/rfc6901>+-}+module Network.JSONApi.Source (+ Source (..)+) where++import Data.Aeson (ToJSON, FromJSON)+import Data.Default (Default, def)+import Data.Text (Text)+import qualified GHC.Generics as G++data Source =+ Source { pointer :: Maybe Text+ , parameter :: Maybe Text+ }+ deriving (Show, Eq, G.Generic)++instance ToJSON Source+instance FromJSON Source++instance Default Source where+ def = Source+ { pointer = Nothing+ , parameter = Nothing+ }
test/Network/JSONApi/ErrorSpec.hs view
@@ -23,6 +23,7 @@ , code = Nothing , title = Nothing , detail = Nothing+ , source = Nothing , meta = Nothing } in (def::Error Int) `shouldBe` expectedDefault
+ test/Network/JSONApi/SourceSpec.hs view
@@ -0,0 +1,34 @@+module Network.JSONApi.SourceSpec where++import qualified Data.Aeson as AE+import qualified Data.ByteString.Lazy.Char8 as BS+import Data.Default (def)+import Data.Maybe+import Network.JSONApi+import Prelude hiding (id)+import TestHelpers (prettyEncode)+import Test.Hspec++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ describe "Defaults" $+ it "provides defaults" $+ let expectedDefault = Source+ { pointer = Nothing+ , parameter = Nothing+ }+ in (def::Source) `shouldBe` expectedDefault++ describe "JSON serialization" $+ it "provides ToJSON/FromJSON instances" $ do+ let testSource = def::Source+ let encJson = BS.unpack . prettyEncode $ testSource+ let decJson = AE.decode (BS.pack encJson) :: Maybe Source++ isJust decJson `shouldBe` True++ -- putStrLn encJson+ -- print (fromJust decJson)