api-tools 0.4 → 0.4.0.1
raw patch · 4 files changed
+51/−33 lines, 4 filesdep ~aesondep ~arraydep ~attoparsecPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: aeson, array, attoparsec, lens, template-haskell
API changes (from Hackage documentation)
- Data.API.JSON: withNum :: Num n => String -> (n -> ParserWithErrs a) -> Value -> ParserWithErrs a
Files
- api-tools.cabal +18/−19
- changelog +18/−0
- src/Data/API/JSON.hs +13/−11
- tests/Data/API/Test/Migration.hs +2/−3
api-tools.cabal view
@@ -1,5 +1,5 @@ Name: api-tools-Version: 0.4+Version: 0.4.0.1 Synopsis: DSL for generating API boilerplate and docs Description: api-tools provides a compact DSL for describing an API. It uses Template Haskell to generate the@@ -15,7 +15,7 @@ Copyright: (c) Iris Connect 2013-2014 Category: Network, Web, Cloud, Distributed Computing Build-type: Simple-+Extra-source-files: changelog Cabal-version: >=1.10 Source-Repository head@@ -25,7 +25,7 @@ Source-Repository this Type: git Location: git://github.com/iconnect/api-tools.git- Tag: 0.4+ Tag: 0.4.0.1 Library Hs-Source-Dirs: src@@ -67,27 +67,26 @@ Build-depends: Cabal >= 1.4 && < 2 , QuickCheck >= 2.5.1 && < 2.8 ,- aeson >= 0.6.2 && < 0.7 ,+ aeson >= 0.6.2 && < 0.9 , aeson-pretty >= 0.1 && < 0.8 ,- array >= 0.4 && < 0.5 ,- attoparsec >= 0.10.4 && < 0.12 ,+ array >= 0.4 && < 0.6 ,+ attoparsec >= 0.10.4 && < 0.13 , base >= 4 && < 5 , base64-bytestring >= 1.0 && < 1.1 , bytestring >= 0.9 && < 0.11 , case-insensitive >= 1.0 && < 1.3 , containers >= 0.5 && < 0.6 ,- lens >= 3.8.7 && < 4 ,+ lens >= 3.8.7 && < 4.4 , old-locale >= 1.0.0.4 && < 1.1 , regex-compat-tdfa >= 0.95.1 && < 0.96 , safe >= 0.3.3 && < 0.4 , safecopy >= 0.8.1 && < 0.9 , time >= 1.4 && < 1.5 ,- template-haskell >= 2.7 && < 2.9 ,+ template-haskell >= 2.7 && < 2.10 , text >= 0.11.3 && < 1.2 , unordered-containers >= 0.2.3.0 && < 0.3 , vector >= 0.10.0.1 && < 0.11 - Build-tools: alex, happy@@ -107,22 +106,22 @@ Build-depends: api-tools, QuickCheck >= 2.5.1 && < 2.8 ,- aeson >= 0.6.2 && < 0.7 ,+ aeson >= 0.6.2 && < 0.9 , aeson-pretty >= 0.1 && < 0.8 ,- array >= 0.4 && < 0.5 ,- attoparsec >= 0.10.4 && < 0.12 ,+ array >= 0.4 && < 0.6 ,+ attoparsec >= 0.10.4 && < 0.13 , base >= 4 && < 5 , base64-bytestring >= 1.0 && < 1.1 , bytestring >= 0.9 && < 0.11 , case-insensitive >= 1.0 && < 1.3 , containers >= 0.5 && < 0.6 ,- lens >= 3.8.7 && < 4 ,+ lens >= 3.8.7 && < 4.4 , old-locale >= 1.0.0.4 && < 1.1 , regex-compat-tdfa >= 0.95.1 && < 0.96 , safe >= 0.3.3 && < 0.4 , safecopy >= 0.8.1 && < 0.9 , time >= 1.4 && < 1.5 ,- template-haskell >= 2.7 && < 2.9 ,+ template-haskell >= 2.7 && < 2.10 , text >= 0.11.3 && < 1.2 , unordered-containers >= 0.2.3.0 && < 0.3 , vector >= 0.10.0.1 && < 0.11@@ -153,16 +152,16 @@ api-tools, Cabal >= 1.4 && < 2 , QuickCheck >= 2.5.1 && < 2.8 ,- aeson >= 0.6.2 && < 0.7 ,+ aeson >= 0.6.2 && < 0.9 , aeson-pretty >= 0.1 && < 0.8 ,- array >= 0.4 && < 0.5 ,- attoparsec >= 0.10.4 && < 0.12 ,+ array >= 0.4 && < 0.6 ,+ attoparsec >= 0.10.4 && < 0.13 , base >= 4 && < 5 , base64-bytestring >= 1.0 && < 1.1 , bytestring >= 0.9 && < 0.11 , case-insensitive >= 1.0 && < 1.3 , containers >= 0.5 && < 0.6 ,- lens >= 3.8.7 && < 4 ,+ lens >= 3.8.7 && < 4.4 , old-locale >= 1.0.0.4 && < 1.1 , regex-compat-tdfa >= 0.95.1 && < 0.96 , safe >= 0.3.3 && < 0.4 ,@@ -171,7 +170,7 @@ tasty-hunit >= 0.2 && < 0.9 , tasty-quickcheck >= 0.3 && < 0.9 , time >= 1.4 && < 1.5 ,- template-haskell >= 2.7 && < 2.9 ,+ template-haskell >= 2.7 && < 2.10 , text >= 0.11.3 && < 1.2 , unordered-containers >= 0.2.3.0 && < 0.3 , vector >= 0.10.0.1 && < 0.11
+ changelog view
@@ -0,0 +1,18 @@+-*-change-log-*-++0.4.0.1 Adam Gundry <adam@well-typed.com> July 2014+ * Widen dependency compatibility to support GHC 7.8.3++0.4 Adam Gundry <adam@well-typed.com> May 2014+ * Support read-only fields and default values in JSON parser+ * Better error messages when parsing unions+ * More accurate version bounds in Cabal file+ * Support custom migrations on non-record types+ * Add instance IsString APIType++0.3 Adam Gundry <adam@well-typed.com> Apr 2014+ * Add tool to perform generic traversals+ * Move API normal forms and dependency analysis to a new module++0.2 Chris Dornan <chrisd@irisconnect.co.uk> Feb 2014+ * First public release
src/Data/API/JSON.hs view
@@ -42,7 +42,6 @@ , expectedString , badFormat , withInt- , withNum , withIntRange , withBinary , withBool@@ -63,9 +62,9 @@ import Control.Applicative import qualified Data.Aeson as JS+import qualified Data.Aeson.Parser as JS import Data.Aeson.TH-import Data.Attoparsec.Number-import Data.Attoparsec.Text+import Data.Attoparsec.ByteString import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Base64 as B64 import qualified Data.ByteString.Lazy as BL@@ -74,6 +73,7 @@ import Data.Maybe import qualified Data.SafeCopy as SC import qualified Data.Text as T+import qualified Data.Text.Encoding as T import Data.Time import Data.Traversable import qualified Data.Vector as V@@ -352,11 +352,13 @@ withInt :: String -> (Int -> ParserWithErrs a) -> JS.Value -> ParserWithErrs a withInt = withNum -withNum :: Num n => String -> (n -> ParserWithErrs a) -> JS.Value -> ParserWithErrs a-withNum _ f (JS.Number (I n)) = f (fromInteger n)-withNum _ f (JS.String s)- | Right (I n) <- parseOnly (number <* endOfInput) s = f (fromInteger n)-withNum s _ v = failWith $ Expected ExpInt s v+withNum :: JS.FromJSON n => String -> (n -> ParserWithErrs a) -> JS.Value -> ParserWithErrs a+withNum s f v = case JS.fromJSON v of+ JS.Success i -> f i+ JS.Error _ | JS.String t <- v+ , Right v' <- parseOnly (JS.value <* endOfInput) (T.encodeUtf8 t)+ , JS.Success i <- JS.fromJSON v' -> f i+ | otherwise -> failWith $ Expected ExpInt s v withIntRange :: IntRange -> String -> (Int -> ParserWithErrs a) -> JS.Value -> ParserWithErrs a@@ -382,9 +384,9 @@ withBool :: String -> (Bool -> ParserWithErrs a) -> JS.Value -> ParserWithErrs a withBool _ f (JS.Bool b) = f b-withBool _ f (JS.Number (I i)) | i == 0 = f False- | i == 1 = f True-withBool s _ v = failWith $ Expected ExpBool s v+withBool _ f (JS.Number x) | x == 0 = f False+ | x == 1 = f True+withBool s _ v = failWith $ Expected ExpBool s v withText :: String -> (T.Text -> ParserWithErrs a) -> JS.Value -> ParserWithErrs a
tests/Data/API/Test/Migration.hs view
@@ -17,7 +17,6 @@ import qualified Data.Aeson as JS import qualified Data.Aeson.Encode.Pretty as JS-import Data.Attoparsec.Number import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Base64 as B64 import qualified Data.ByteString.Lazy.Char8 as BL@@ -60,8 +59,8 @@ i <- HMap.lookup "id" x ?! CustomMigrationError "missing id" (JS.Object x) b <- HMap.lookup "c" x ?! CustomMigrationError "missing b" (JS.Object x) r <- case (i, b) of- (JS.Number (I j), JS.String t)- -> return $ JS.String $ t `T.append` T.pack (show j)+ (JS.Number j, JS.String t)+ -> return $ JS.String $ t `T.append` T.pack (show (round j :: Int)) _ -> Left $ CustomMigrationError "bad data" (JS.Object x) return $ HMap.insert "c" r x testRecordMigration DuplicateNew = mkRecordMigration $ \ x -> do