json-autotype 0.4 → 0.5
raw patch · 5 files changed
+41/−23 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Aeson.AutoType.Format: normalizeTypeName :: Text -> Text
Files
- Data/Aeson/AutoType/CodeGen.hs +10/−6
- Data/Aeson/AutoType/Format.hs +12/−7
- README.md +2/−1
- changelog.md +6/−0
- json-autotype.cabal +11/−9
Data/Aeson/AutoType/CodeGen.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ViewPatterns #-} -- | Wrappers for generating prologue and epilogue code in Haskell. module Data.Aeson.AutoType.CodeGen( writeHaskellModule@@ -9,6 +10,7 @@ import qualified Data.Text.IO as Text import Data.Text import qualified Data.HashMap.Strict as Map+import Control.Arrow (first) import System.FilePath import System.IO @@ -44,9 +46,8 @@ ,"import Control.Applicative" ,"import Data.Aeson.AutoType.Alternative" ,"import Data.Aeson(decode, Value(..), FromJSON(..), ToJSON(..),"- ," (.:), (.:?), (.!=), (.=), object)"+ ," (.:), (.:?), (.=), object)" ,"import Data.Text (Text)"- ,"import Data.Aeson.TH" ,"import GHC.Generics" ,""] @@ -82,8 +83,11 @@ Text.hPutStrLn hOut $ displaySplitTypes types Text.hPutStrLn hOut epilogue where- (moduleName, extension) = splitExtension $- if outputFilename == "-"- then defaultOutputFilename- else outputFilename+ (moduleName, extension) =+ first normalizeTypeName' $+ splitExtension $+ if outputFilename == "-"+ then defaultOutputFilename+ else outputFilename+ normalizeTypeName' = Text.unpack . normalizeTypeName . Text.pack
Data/Aeson/AutoType/Format.hs view
@@ -7,10 +7,12 @@ -- | Formatting type declarations and class instances for inferred types. module Data.Aeson.AutoType.Format( displaySplitTypes, splitTypeByLabel, unificationCandidates,- unifyCandidates+ unifyCandidates,+ normalizeTypeName ) where import Control.Arrow ((&&&))+import Control.Applicative ((<$>), (<*>)) import Control.Lens.TH import Control.Lens import Control.Monad (forM)@@ -241,13 +243,16 @@ formatObjectType (normalizeTypeName name) typ normalizeTypeName :: Text -> Text-normalizeTypeName = escapeKeywords .- escapeFirstNonAlpha .- Text.concat .- map capitalize .- filter (not . Text.null) .- Text.split (not . acceptableInVariable)+normalizeTypeName s = ifEmpty "JsonEmptyKey" .+ escapeKeywords .+ escapeFirstNonAlpha .+ Text.concat .+ map capitalize .+ filter (not . Text.null) .+ Text.split (not . acceptableInVariable) $ s where+ ifEmpty x "" = x+ ifEmpty _ nonEmpty = nonEmpty acceptableInVariable c = isAlpha c || isDigit c escapeFirstNonAlpha cs | Text.null cs = cs escapeFirstNonAlpha cs@(Text.head -> c) | isAlpha c = cs
README.md view
@@ -8,8 +8,9 @@ I should probably write a short paper to explain the methodology. -[](https://travis-ci.org/mgajda/json-autotype)+[](https://travis-ci.org/mgajda/json-autotype) [](https://hackage.haskell.org/package/json-autotype)+[](http://packdeps.haskellers.com/feed?needle=json-autotype) Details on official releases are on [Hackage](https://hackage.haskell.org/package/json-autotype)
changelog.md view
@@ -1,5 +1,11 @@ Changelog =========+ 0.5 Apr 2015++ * Reduced name space pollution when generating code.+ Now all valid JSON test examples do work.+ * Corrected build failure on GHC 7.8.4+ 0.4 Apr 2015 * Release candidate for current functionality.
json-autotype.cabal view
@@ -1,6 +1,6 @@ -- Build information for the package. name: json-autotype-version: 0.4+version: 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.@@ -32,7 +32,7 @@ extra-source-files: README.md changelog.md cabal-version: >=1.10 bug-reports: https://github.com/mgajda/json-autotype/issues-tested-with: GHC==7.8.4+tested-with: GHC==7.8.4,GHC==7.10.1,GHC==7.6.3 source-repository head type: git@@ -109,10 +109,12 @@ -- hs-source-dirs: default-language: Haskell2010 --- test suites-test-suite json-autotype-random-test+-- * Test suites+-- Test suite with QuickCheck on random values,+-- and extracted types.+test-suite json-autotype-qc-test type: exitcode-stdio-1.0- main-is: GenerateTestJSON.hs+ main-is: TestQC.hs other-modules: Data.Aeson.AutoType.Util, Data.Aeson.AutoType.Test, Data.Aeson.AutoType.Type@@ -132,7 +134,6 @@ directory >=1.1 && <1.3, filepath >=1.3 && <1.5, hashable >=1.2 && <1.3,- hflags >=0.3 && <0.5, lens >=4.1 && <4.10, mtl >=2.1 && <2.3, pretty >=1.1 && <1.3,@@ -147,10 +148,10 @@ -- hs-source-dirs: default-language: Haskell2010 --- test suite with QuickCheck-test-suite json-autotype-qc-test+-- Test suite with Haskell code generation and compilation+test-suite json-autotype-random-test type: exitcode-stdio-1.0- main-is: TestQC.hs+ main-is: GenerateTestJSON.hs other-modules: Data.Aeson.AutoType.Util, Data.Aeson.AutoType.Test, Data.Aeson.AutoType.Type@@ -170,6 +171,7 @@ directory >=1.1 && <1.3, filepath >=1.3 && <1.5, hashable >=1.2 && <1.3,+ hflags >=0.3 && <0.5, lens >=4.1 && <4.10, mtl >=2.1 && <2.3, pretty >=1.1 && <1.3,