Skip to content

Commit

Permalink
Compatibility with aeson 1.5 (#368)
Browse files Browse the repository at this point in the history
* Compatibility with aeson 1.5

* Lower bound for aeson to 1.5

Co-authored-by: Fendor <[email protected]>
  • Loading branch information
wz1000 and fendor authored Sep 13, 2022
1 parent ba6d3b3 commit 58cbd64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hie-bios.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Library
autogen-modules: Paths_hie_bios
Build-Depends:
base >= 4.8 && < 5,
aeson >= 2.0 && < 2.2,
aeson >= 1.5 && < 2.2,
base16-bytestring >= 0.1.1 && < 1.1,
bytestring >= 0.10.8 && < 0.12,
co-log-core ^>= 0.3.0,
Expand Down
20 changes: 20 additions & 0 deletions src/HIE/Bios/Config/YAML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}

-- | Datatypes for parsing @hie.yaml@ files
module HIE.Bios.Config.YAML
Expand All @@ -22,13 +23,32 @@ module HIE.Bios.Config.YAML

import Control.Applicative ((<|>))
import Data.Aeson
#if MIN_VERSION_aeson(2,0,0)
import Data.Aeson.KeyMap (keys)
#else
import qualified Data.HashMap.Strict as Map
import qualified Data.Text as T
#endif
import Data.Aeson.Types (Object, Parser, Value (Null),
typeMismatch)
import qualified Data.Char as C (toLower)
import Data.List ((\\))
import GHC.Generics (Generic)

#if !MIN_VERSION_aeson(2,0,0)
-- | Backwards compatible type-def for Key
-- This used to be just a Text, but since aeson >= 2
-- this is an opaque datatype.
type Key = T.Text
-- | Backwards compatible type-def for KeyMap
-- This used to be just a HashMap, but since aeson >= 2
-- this is an opaque datatype.
type KeyMap v = Map.HashMap T.Text v

keys :: KeyMap v -> [Key]
keys = Map.keys
#endif

checkObjectKeys :: [Key] -> Object -> Parser ()
checkObjectKeys allowedKeys obj =
let extraKeys = keys obj \\ allowedKeys
Expand Down

0 comments on commit 58cbd64

Please sign in to comment.