packages feed

aeson-injector 1.0.2.0 → 1.0.3.0

raw patch · 2 files changed

+19/−1 lines, 2 filesdep +servant-docsPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: servant-docs

API changes (from Hackage documentation)

- Data.Aeson.WithField: instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (Data.Aeson.WithField.WithField s a b)
- Data.Aeson.WithField: instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (Data.Aeson.WithField.WithFields a b)
- Data.Aeson.WithField: instance (GHC.Read.Read a, GHC.Read.Read b) => GHC.Read.Read (Data.Aeson.WithField.WithField s a b)
- Data.Aeson.WithField: instance (GHC.Read.Read a, GHC.Read.Read b) => GHC.Read.Read (Data.Aeson.WithField.WithFields a b)
- Data.Aeson.WithField: instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (Data.Aeson.WithField.WithField s a b)
- Data.Aeson.WithField: instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (Data.Aeson.WithField.WithFields a b)
+ Data.Aeson.WithField: instance (GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Data.Aeson.WithField.WithField s a b)
+ Data.Aeson.WithField: instance (GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Data.Aeson.WithField.WithFields a b)
+ Data.Aeson.WithField: instance (GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Data.Aeson.WithField.WithField s a b)
+ Data.Aeson.WithField: instance (GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Data.Aeson.WithField.WithFields a b)
+ Data.Aeson.WithField: instance (GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Data.Aeson.WithField.WithField s a b)
+ Data.Aeson.WithField: instance (GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Data.Aeson.WithField.WithFields a b)
+ Data.Aeson.WithField: instance (Servant.Docs.Internal.ToSample a, Servant.Docs.Internal.ToSample b) => Servant.Docs.Internal.ToSample (Data.Aeson.WithField.WithField s a b)
+ Data.Aeson.WithField: instance (Servant.Docs.Internal.ToSample a, Servant.Docs.Internal.ToSample b) => Servant.Docs.Internal.ToSample (Data.Aeson.WithField.WithFields a b)
+ Data.Aeson.WithField: instance Servant.Docs.Internal.ToSample a => Servant.Docs.Internal.ToSample (Data.Aeson.WithField.OnlyField s a)

Files

aeson-injector.cabal view
@@ -1,5 +1,5 @@ name:                aeson-injector-version:             1.0.2.0+version:             1.0.3.0 synopsis:            Injecting fields into aeson values description:         See README.md license:             MIT@@ -36,6 +36,7 @@     , swagger2             >= 2.0   && < 3.0     , text                 >= 1.2   && < 2.0     , unordered-containers >= 0.2.7 && < 0.3+    , servant-docs         >= 0.7   && < 0.9  test-suite test-aeson-injector   default-language: Haskell2010
src/Data/Aeson/WithField.hs view
@@ -169,6 +169,7 @@ import Data.Swagger  import GHC.Generics  import GHC.TypeLits +import Servant.Docs   import qualified Data.HashMap.Strict as H  import qualified Data.Text as T @@ -206,6 +207,12 @@ -- behaves as it is 'a' but with additional 'id' field. type WithId i a = WithField "id" i a  +instance (ToSample a, ToSample b) => ToSample (WithField s a b) where +  toSamples _ = samples $ WithField <$> as <*> bs +    where +    as = snd <$> toSamples (Proxy :: Proxy a)+    bs = snd <$> toSamples (Proxy :: Proxy b)+ -- | Note: the instance injects field only in 'Object' case. -- In other cases it forms a wrapper around the 'Value' produced  -- by 'toJSON' of inner 'b' body.@@ -286,6 +293,11 @@ instance Bifunctor WithFields where    bimap fa fb (WithFields a b) = WithFields (fa a) (fb b) +instance (ToSample a, ToSample b) => ToSample (WithFields a b) where +  toSamples _ = samples $ WithFields <$> as <*> bs +    where +    as = snd <$> toSamples (Proxy :: Proxy a)+    bs = snd <$> toSamples (Proxy :: Proxy b)  -- | Note: the instance injects field only in 'Object' case. -- In other cases it forms a wrapper around the 'Value' produced @@ -372,6 +384,11 @@  instance Functor (OnlyField s) where    fmap f (OnlyField a) = OnlyField (f a)++instance ToSample a => ToSample (OnlyField s a) where +  toSamples _ = samples $ OnlyField <$> as+    where +    as = snd <$> toSamples (Proxy :: Proxy a)  instance (KnownSymbol s, ToJSON a) => ToJSON (OnlyField s a) where    toJSON (OnlyField a) = object [ field .= a ]