-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from biocad/maksbotan/aeson-2
Support aeson-2
- Loading branch information
Showing
11 changed files
with
182 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
branches: master | ||
|
||
constraint-set aeson-1 | ||
constraints: aeson <2.0 | ||
|
||
constraint-set aeson-2 | ||
constraints: aeson >=2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{-# LANGUAGE CPP #-} | ||
|
||
module Data.OpenApi.Aeson.Compat where | ||
|
||
#if MIN_VERSION_aeson(2,0,0) | ||
import Data.Aeson (Key) | ||
import qualified Data.Aeson.Key as Key | ||
import qualified Data.Aeson.KeyMap as KeyMap | ||
#else | ||
import qualified Data.HashMap.Strict as HM | ||
#endif | ||
import Data.Bifunctor (first) | ||
import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap | ||
import qualified Data.Text as T | ||
|
||
#if MIN_VERSION_aeson(2,0,0) | ||
deleteKey :: Key -> KeyMap.KeyMap v -> KeyMap.KeyMap v | ||
deleteKey = KeyMap.delete | ||
|
||
objectToList :: KeyMap.KeyMap v -> [(Key, v)] | ||
objectToList = KeyMap.toList | ||
|
||
objectKeys :: KeyMap.KeyMap v -> [T.Text] | ||
objectKeys = map Key.toText . KeyMap.keys | ||
|
||
stringToKey :: String -> Key | ||
stringToKey = Key.fromString | ||
|
||
keyToString :: Key -> String | ||
keyToString = Key.toString | ||
|
||
keyToText :: Key -> T.Text | ||
keyToText = Key.toText | ||
|
||
toInsOrdHashMap :: KeyMap.KeyMap v -> InsOrdHashMap.InsOrdHashMap T.Text v | ||
toInsOrdHashMap = InsOrdHashMap.fromList . fmap (first Key.toText) . KeyMap.toList | ||
|
||
fromInsOrdHashMap :: InsOrdHashMap.InsOrdHashMap T.Text v -> KeyMap.KeyMap v | ||
fromInsOrdHashMap = KeyMap.fromList . fmap (first Key.fromText) . InsOrdHashMap.toList | ||
|
||
lookupKey :: T.Text -> KeyMap.KeyMap v -> Maybe v | ||
lookupKey = KeyMap.lookup . Key.fromText | ||
|
||
hasKey :: T.Text -> KeyMap.KeyMap a -> Bool | ||
hasKey = KeyMap.member . Key.fromText | ||
#else | ||
deleteKey :: T.Text -> HM.HashMap T.Text v -> HM.HashMap T.Text v | ||
deleteKey = HM.delete | ||
|
||
objectToList :: HM.HashMap T.Text v -> [(T.Text, v)] | ||
objectToList = HM.toList | ||
|
||
objectKeys :: HM.HashMap T.Text v -> [T.Text] | ||
objectKeys = HM.keys | ||
|
||
stringToKey :: String -> T.Text | ||
stringToKey = T.pack | ||
|
||
keyToString :: T.Text -> String | ||
keyToString = T.unpack | ||
|
||
keyToText :: T.Text -> T.Text | ||
keyToText = id | ||
|
||
toInsOrdHashMap :: HM.HashMap T.Text v -> InsOrdHashMap.InsOrdHashMap T.Text v | ||
toInsOrdHashMap = InsOrdHashMap.fromHashMap | ||
|
||
fromInsOrdHashMap :: InsOrdHashMap.InsOrdHashMap T.Text v -> HM.HashMap T.Text v | ||
fromInsOrdHashMap = InsOrdHashMap.toHashMap | ||
|
||
lookupKey :: T.Text -> HM.HashMap T.Text v -> Maybe v | ||
lookupKey = HM.lookup | ||
|
||
hasKey :: T.Text -> HM.HashMap T.Text a -> Bool | ||
hasKey = HM.member | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.