json-autotype 1.0.6 → 1.0.7
raw patch · 4 files changed
+30/−10 lines, 4 filesdep ~lensdep ~vectorPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: lens, vector
API changes (from Hackage documentation)
- Data.Aeson.AutoType.Alternative: [AltLeft] :: a -> (:|:) a b
- Data.Aeson.AutoType.Alternative: [AltRight] :: b -> (:|:) a b
- Data.Aeson.AutoType.Extract: [Dict] :: Map Text Type -> Dict
- Data.Aeson.AutoType.Extract: [TArray] :: Type -> Type
- Data.Aeson.AutoType.Extract: [TBool] :: Type
- Data.Aeson.AutoType.Extract: [TLabel] :: Text -> Type
- Data.Aeson.AutoType.Extract: [TNull] :: Type
- Data.Aeson.AutoType.Extract: [TNum] :: Type
- Data.Aeson.AutoType.Extract: [TObj] :: Dict -> Type
- Data.Aeson.AutoType.Extract: [TString] :: Type
- Data.Aeson.AutoType.Extract: [TUnion] :: (Set Type) -> Type
- Data.Aeson.AutoType.Extract: [unDict] :: Dict -> Map Text Type
- Data.Aeson.AutoType.Plugin.Subtype: [SubtypeDesc] :: String -> Type -> (String -> String) -> String -> Dynamic -> SubtypeDesc
- Data.Aeson.AutoType.Plugin.Subtype: [SubtypePlugin] :: ([Value] -> Maybe SubtypeDesc) -> (SubtypeDesc -> SubtypeDesc -> Either SubtypeDesc Type) -> SubtypePlugin
- Data.Aeson.AutoType.Plugin.Subtype: [declare] :: SubtypeDesc -> String
- Data.Aeson.AutoType.Plugin.Subtype: [detect] :: SubtypePlugin -> [Value] -> Maybe SubtypeDesc
- Data.Aeson.AutoType.Plugin.Subtype: [reference] :: SubtypeDesc -> String -> String
- Data.Aeson.AutoType.Plugin.Subtype: [subtypeClass] :: SubtypeDesc -> Type
- Data.Aeson.AutoType.Plugin.Subtype: [subtypeName] :: SubtypeDesc -> String
- Data.Aeson.AutoType.Plugin.Subtype: [typeInfo] :: SubtypeDesc -> Dynamic
- Data.Aeson.AutoType.Plugin.Subtype: [unify] :: SubtypePlugin -> SubtypeDesc -> SubtypeDesc -> Either SubtypeDesc Type
- Data.Aeson.AutoType.Type: [Dict] :: Map Text Type -> Dict
- Data.Aeson.AutoType.Type: [TArray] :: Type -> Type
- Data.Aeson.AutoType.Type: [TBool] :: Type
- Data.Aeson.AutoType.Type: [TLabel] :: Text -> Type
- Data.Aeson.AutoType.Type: [TNull] :: Type
- Data.Aeson.AutoType.Type: [TNum] :: Type
- Data.Aeson.AutoType.Type: [TObj] :: Dict -> Type
- Data.Aeson.AutoType.Type: [TString] :: Type
- Data.Aeson.AutoType.Type: [TUnion] :: (Set Type) -> Type
- Data.Aeson.AutoType.Type: [unDict] :: Dict -> Map Text Type
+ Data.Aeson.AutoType.Alternative: AltLeft :: a -> (:|:) a b
+ Data.Aeson.AutoType.Alternative: AltRight :: b -> (:|:) a b
+ Data.Aeson.AutoType.Extract: Dict :: Map Text Type -> Dict
+ Data.Aeson.AutoType.Extract: TArray :: Type -> Type
+ Data.Aeson.AutoType.Extract: TBool :: Type
+ Data.Aeson.AutoType.Extract: TLabel :: Text -> Type
+ Data.Aeson.AutoType.Extract: TNull :: Type
+ Data.Aeson.AutoType.Extract: TNum :: Type
+ Data.Aeson.AutoType.Extract: TObj :: Dict -> Type
+ Data.Aeson.AutoType.Extract: TString :: Type
+ Data.Aeson.AutoType.Extract: TUnion :: (Set Type) -> Type
+ Data.Aeson.AutoType.Extract: unDict :: Dict -> Map Text Type
+ Data.Aeson.AutoType.Plugin.Subtype: SubtypeDesc :: String -> Type -> (String -> String) -> String -> Dynamic -> SubtypeDesc
+ Data.Aeson.AutoType.Plugin.Subtype: SubtypePlugin :: ([Value] -> Maybe SubtypeDesc) -> (SubtypeDesc -> SubtypeDesc -> Either SubtypeDesc Type) -> SubtypePlugin
+ Data.Aeson.AutoType.Plugin.Subtype: declare :: SubtypeDesc -> String
+ Data.Aeson.AutoType.Plugin.Subtype: detect :: SubtypePlugin -> [Value] -> Maybe SubtypeDesc
+ Data.Aeson.AutoType.Plugin.Subtype: reference :: SubtypeDesc -> String -> String
+ Data.Aeson.AutoType.Plugin.Subtype: subtypeClass :: SubtypeDesc -> Type
+ Data.Aeson.AutoType.Plugin.Subtype: subtypeName :: SubtypeDesc -> String
+ Data.Aeson.AutoType.Plugin.Subtype: typeInfo :: SubtypeDesc -> Dynamic
+ Data.Aeson.AutoType.Plugin.Subtype: unify :: SubtypePlugin -> SubtypeDesc -> SubtypeDesc -> Either SubtypeDesc Type
+ Data.Aeson.AutoType.Type: Dict :: Map Text Type -> Dict
+ Data.Aeson.AutoType.Type: TArray :: Type -> Type
+ Data.Aeson.AutoType.Type: TBool :: Type
+ Data.Aeson.AutoType.Type: TLabel :: Text -> Type
+ Data.Aeson.AutoType.Type: TNull :: Type
+ Data.Aeson.AutoType.Type: TNum :: Type
+ Data.Aeson.AutoType.Type: TObj :: Dict -> Type
+ Data.Aeson.AutoType.Type: TString :: Type
+ Data.Aeson.AutoType.Type: TUnion :: (Set Type) -> Type
+ Data.Aeson.AutoType.Type: instance Typeable Dict
+ Data.Aeson.AutoType.Type: instance Typeable Type
+ Data.Aeson.AutoType.Type: unDict :: Dict -> Map Text Type
Files
- GenerateJSONParser.hs +12/−1
- README.md +5/−0
- changelog.md +4/−0
- json-autotype.cabal +9/−9
GenerateJSONParser.hs view
@@ -38,6 +38,7 @@ defineFlag "t:test" False "Try to run generated parser after" defineFlag "d:debug" False "Set this flag to see more debugging info" defineFlag "y:typecheck" True "Set this flag to typecheck after unification"+defineFlag "p:preprocessor" False "Work as GHC preprocessor (skip preprocessor pragma)" defineFlag "fakeFlag" True "Ignore this flag - it doesn't exist!!! It is workaround to library problem." -- | Works like @Debug.trace@ when the --debug flag is enabled, and does nothing otherwise.@@ -60,7 +61,7 @@ extractTypeFromJSONFile inputFilename = withFileOrHandle inputFilename ReadMode stdin $ \hIn -> -- First we decode JSON input into Aeson's Value type- do bs <- BSL.hGetContents hIn+ do bs <- preprocess <$> BSL.hGetContents hIn Text.hPutStrLn stderr $ "Processing " `Text.append` Text.pack (show inputFilename) myTrace ("Decoded JSON: " ++ pretty (decode bs :: Maybe Value)) case decode bs of@@ -73,6 +74,16 @@ (v `typeCheck` t) `unless` fatal ("Typecheck against base type failed for " `Text.append` Text.pack inputFilename) return $ Just (inputFilename, t, v)++-- | Perform preprocessing of JSON input to drop initial pragma.+preprocess :: BSL.ByteString -> BSL.ByteString+preprocess | flags_preprocessor = dropPragma+ | otherwise = id++-- | Drop initial pragma.+dropPragma :: BSL.ByteString -> BSL.ByteString+dropPragma input | "{-#" `BSL.isPrefixOf` input = BSL.dropWhile (/='\n') input+ | otherwise = input -- | Type checking all input files with given type, -- and return a list of filenames for files that passed the check.
README.md view
@@ -109,3 +109,8 @@ ``` Real-world use case examples are provided in the package [source repository](https://github.com/mgajda/json-autotype/tree/master/test).++Other approaches:+=================++There is a [json-sampler](https://maxs.io/generating-types-from-json-samples/) that allows to make simpler data structure from JSON examples, but doesn't seem to perform unification, nor is it suitable for big APIs.
changelog.md view
@@ -1,5 +1,9 @@ Changelog =========+ 1.0.7 Jul 2015++ * Dependency bump for lens and vector.+ 1.0.6 Jun 2015 * Make lens and aeson versions consistent in the *.cabal file.
json-autotype.cabal view
@@ -1,6 +1,6 @@ -- Build information for the package. name: json-autotype-version: 1.0.6+version: 1.0.7 synopsis: Automatic type declaration for JSON input data description: Generates datatype declarations with Aeson's "FromJSON" instances from a set of example ".json" files.@@ -69,7 +69,7 @@ hashable >=1.2 && <1.3, hint >=0.3 && <0.5, hflags >=0.3 && <0.5,- lens >=4.1 && <4.12,+ lens >=4.1 && <4.13, mtl >=2.1 && <2.3, pretty >=1.1 && <1.3, process >=1.1 && <1.4,@@ -77,7 +77,7 @@ text >=1.1 && <1.4, uniplate >=1.6 && <1.7, unordered-containers >=0.2 && <0.3,- vector >=0.9 && <0.11+ vector >=0.9 && <0.12 default-language: Haskell2010 executable json-autotype@@ -108,7 +108,7 @@ hashable >=1.2 && <1.3, hint >=0.4 && <0.5, hflags >=0.3 && <0.5,- lens >=4.1 && <4.12,+ lens >=4.1 && <4.13, mtl >=2.1 && <2.3, pretty >=1.1 && <1.3, process >=1.1 && <1.4,@@ -116,7 +116,7 @@ text >=1.1 && <1.4, uniplate >=1.6 && <1.7, unordered-containers >=0.2 && <0.3,- vector >=0.9 && <0.11+ vector >=0.9 && <0.12 -- hs-source-dirs: default-language: Haskell2010 @@ -147,7 +147,7 @@ directory >=1.1 && <1.3, filepath >=1.3 && <1.5, hashable >=1.2 && <1.3,- lens >=4.1 && <4.12,+ lens >=4.1 && <4.13, mtl >=2.1 && <2.3, pretty >=1.1 && <1.3, process >=1.1 && <1.4,@@ -156,7 +156,7 @@ text >=1.1 && <1.4, uniplate >=1.6 && <1.7, unordered-containers >=0.2 && <0.3,- vector >=0.9 && <0.11,+ vector >=0.9 && <0.12, QuickCheck >=2.4 && <3.0 -- hs-source-dirs: default-language: Haskell2010@@ -189,7 +189,7 @@ filepath >=1.3 && <1.5, hashable >=1.2 && <1.3, hflags >=0.3 && <0.5,- lens >=4.1 && <4.12,+ lens >=4.1 && <4.13, mtl >=2.1 && <2.3, pretty >=1.1 && <1.3, process >=1.1 && <1.4,@@ -198,7 +198,7 @@ text >=1.1 && <1.4, uniplate >=1.6 && <1.7, unordered-containers >=0.2 && <0.3,- vector >=0.9 && <0.11,+ vector >=0.9 && <0.12, QuickCheck >=2.4 && <3.0 -- hs-source-dirs: default-language: Haskell2010