json-autotype 1.0.4 → 1.0.5
raw patch · 9 files changed
+23/−19 lines, 9 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Data/Aeson/AutoType/CodeGen.hs +0/−1
- Data/Aeson/AutoType/Format.hs +8/−2
- Data/Aeson/AutoType/Pretty.hs +1/−2
- Data/Aeson/AutoType/Type.hs +0/−1
- GenerateJSONParser.hs +3/−6
- GenerateTestJSON.hs +3/−5
- TestQC.hs +2/−1
- changelog.md +5/−0
- json-autotype.cabal +1/−1
Data/Aeson/AutoType/CodeGen.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE ViewPatterns #-} -- | Wrappers for generating prologue and epilogue code in Haskell. module Data.Aeson.AutoType.CodeGen( writeHaskellModule
Data/Aeson/AutoType/Format.hs view
@@ -102,8 +102,8 @@ Text.concat [" toJSON (", identifier, " {", wildcard, "}) = object [", inner, "]"] ] where- wildcard | length contents == 0 = ""- | otherwise = ".."+ wildcard | null contents = ""+ | otherwise = ".." inner = ", " `Text.intercalate` map putValue contents putValue (jsonId, haskellId, _typeText, _nullable) = Text.unwords [escapeText jsonId, ".=", haskellId]@@ -242,6 +242,12 @@ forM (toposort dict) $ \(name, typ) -> formatObjectType (normalizeTypeName name) typ +-- | Normalize type name by:+-- 1. Treating all characters that are not acceptable in Haskell variable name as end of word.+-- 2. Capitalizing each word, but a first (camelCase).+-- 3. Adding underscore if first character is non-alphabetic.+-- 4. Escaping Haskell keywords if the whole identifier is such keyword.+-- 5. If identifier is empty, then substituting "JsonEmptyKey" for its name. normalizeTypeName :: Text -> Text normalizeTypeName s = ifEmpty "JsonEmptyKey" . escapeKeywords .
Data/Aeson/AutoType/Pretty.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DeriveGeneric #-}@@ -45,7 +44,7 @@ instance (Out a, Out b) => Out (HashMap a b) where doc (Hash.toList -> dict) = (foldl ($$) "{" $ map formatPair dict)- $$ nest 1 "}"+ $$ nest 1 "}" docPrec _ = doc
Data/Aeson/AutoType/Type.hs view
@@ -2,7 +2,6 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE ViewPatterns #-} {-# LANGUAGE OverloadedStrings #-} -- | Union types describing JSON objects, and operations for querying these types. module Data.Aeson.AutoType.Type(typeSize,
GenerateJSONParser.hs view
@@ -8,14 +8,13 @@ module Main where import Control.Applicative-import Control.Monad+import Control.Monad (forM_, when, unless) import Data.Maybe import Data.List (partition) import System.Exit import System.IO (stdin, stderr, stdout, IOMode(..)) import System.FilePath (splitExtension) import System.Process (system)-import Control.Monad (forM_, when) import qualified Data.ByteString.Lazy.Char8 as BSL import qualified Data.HashMap.Strict as Map import Data.Aeson@@ -43,9 +42,7 @@ -- | Works like @Debug.trace@ when the --debug flag is enabled, and does nothing otherwise. myTrace :: String -> IO ()-myTrace msg = if flags_debug- then putStrLn msg- else return ()+myTrace msg = flags_debug `when` putStrLn msg -- | Report an error to error output. report :: Text -> IO ()@@ -81,7 +78,7 @@ -- and return a list of filenames for files that passed the check. typeChecking :: Type -> [FilePath] -> [Value] -> IO [FilePath] typeChecking ty filenames values = do- when (not $ null failures ) $ report $ Text.unwords $ "Failed to typecheck with unified type: ":+ unless (null failures) $ report $ Text.unwords $ "Failed to typecheck with unified type: ": (Text.pack `map` failures) when ( null successes) $ fatal "No files passed the typecheck." return successes
GenerateTestJSON.hs view
@@ -56,9 +56,7 @@ -- Tracing is switched off: myTrace :: String -> IO ()-myTrace msg = if flags_debug- then putStrLn msg- else return ()+myTrace msg = flags_debug `when` putStrLn msg -- | Report an error to error output. report :: Text -> IO ()@@ -92,7 +90,7 @@ <$> infiniteListOf gen removeDuplicates :: Ord a => [a] -> [a]-removeDuplicates list = fst $ filterM checkDup list `runState` Set.empty+removeDuplicates list = filterM checkDup list `evalState` Set.empty where checkDup x = do seen <- State.get if x `Set.member` seen@@ -156,7 +154,7 @@ writeHaskellModule outputFilename unified if flags_test then do- r <- (==ExitSuccess) <$> system (unwords $ ["runghc", outputFilename, inputFilename])+ r <- (==ExitSuccess) <$> system (unwords ["runghc", outputFilename, inputFilename]) when r $ mapM_ removeFile [inputFilename, outputFilename] return r else
TestQC.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE TemplateHaskell #-}+-- | QuickCheck instances for automatically generating JSON inputs,+-- and checking that json-autotype works correctly on these. module Main( main ) where
changelog.md view
@@ -1,5 +1,10 @@ Changelog =========+ 1.0.3-1.0.5 Jun 2015++ * Bumped Aeson dependency up.+ * Tiny docs corrections.+ 1.0.2 Jun 2015 * Relaxed dependency for lens-4.11.
json-autotype.cabal view
@@ -1,6 +1,6 @@ -- Build information for the package. name: json-autotype-version: 1.0.4+version: 1.0.5 synopsis: Automatic type declaration for JSON input data description: Generates datatype declarations with Aeson's "FromJSON" instances from a set of example ".json" files.