packages feed

json-schema 0.4 → 0.5

raw patch · 5 files changed

+82/−39 lines, 5 filesdep +unordered-containersdep +vectornew-uploaderPVP ok

version bump matches the API change (PVP)

Dependencies added: unordered-containers, vector

API changes (from Hackage documentation)

+ Data.JSON.Schema.Types: Any :: Value
+ Data.JSON.Schema.Types: Map :: Value -> Value
+ Data.JSON.Schema.Types: instance (IsString k, JSONSchema v) => JSONSchema (HashMap k v)
+ Data.JSON.Schema.Types: instance (IsString k, JSONSchema v) => JSONSchema (Map k v)
+ Data.JSON.Schema.Types: instance JSONSchema a => JSONSchema (Vector a)

Files

+ CHANGELOG.md view
@@ -0,0 +1,6 @@+## 0.5++* `JSONSchema` instances for `Data.Vector`, `Data.Map`, and `Data.HashMap`+* Add `Map` type for json objects with arbitrary keys+* Add `Any` type for any json value+* Don't generate empty field names in ojbects for constructors without labeled fields
+ README.md view
@@ -0,0 +1,3 @@+# json-schema++[![Build Status](https://travis-ci.org/silkapp/json-schema.svg?branch=master)](https://travis-ci.org/silkapp/json-schema)
json-schema.cabal view
@@ -1,31 +1,40 @@-Name:                json-schema-Version:             0.4-Synopsis:            Types and type classes for defining JSON schemas.-Description:         Types and type classes for defining JSON schemas.-License:             BSD3-License-file:        LICENSE-Author:              Silk-Maintainer:          code@silk.co-Category:            Data-Build-type:          Simple-Cabal-version:       >=1.6+name:                json-schema+version:             0.5+synopsis:            Types and type classes for defining JSON schemas.+description:         Types and type classes for defining JSON schemas.+license:             BSD3+license-file:        LICENSE+author:              Silk+maintainer:          code@silk.co+category:            Data+build-type:          Simple+cabal-version:       >=1.6 -Library-  Hs-Source-Dirs:    src-  Exposed-Modules:   Data.JSON.Schema-                   , Data.JSON.Schema.Combinators-                   , Data.JSON.Schema.Generic-                   , Data.JSON.Schema.Types-  Build-Depends:     base == 4.*-                   , aeson >= 0.6 && < 0.8-                   , containers >= 0.3 && < 0.6-                   , generic-aeson == 0.1.*-                   , generic-deriving == 1.6.*-                   , tagged >= 0.2 && < 0.8-                   -- No bounds, since we only use the Text type.-                   , text-  Ghc-Options:       -Wall+extra-source-files:+  CHANGELOG.md+  LICENSE+  README.md -Source-repository head-  Type:              Git-  Location:          https://github.com/silkapp/json-schema.git+source-repository head+  type:              git+  location:          https://github.com/silkapp/json-schema.git++library+  ghc-options:       -Wall+  hs-source-dirs:    src+  exposed-modules:+    Data.JSON.Schema+    Data.JSON.Schema.Combinators+    Data.JSON.Schema.Generic+    Data.JSON.Schema.Types+  build-depends:+      base == 4.*+    , aeson >= 0.6 && < 0.8+    , containers >= 0.3 && < 0.6+    , generic-aeson == 0.1.*+    , generic-deriving == 1.6.*+    , tagged >= 0.2 && < 0.8+    -- No bounds, since we only use the Text type.+    , text+    , unordered-containers == 0.2.*+    , vector == 0.10.*
src/Data/JSON/Schema/Generic.hs view
@@ -1,11 +1,12 @@-{-# LANGUAGE TypeOperators-           , TupleSections-           , ScopedTypeVariables-           , FlexibleContexts-           , FlexibleInstances-           , OverlappingInstances-           , TypeFamilies-           #-}+{-# LANGUAGE+    FlexibleContexts+  , FlexibleInstances+  , OverlappingInstances+  , ScopedTypeVariables+  , TupleSections+  , TypeFamilies+  , TypeOperators+  #-} -- | Generic derivation of schemas. The schemas generated match the -- JSON generated by type 'generic-aeson' package. See that package -- for documentation on the format and examples of it.@@ -76,11 +77,16 @@ instance (Selector c, JSONSchema a) => GJSONSCHEMA (M1 S c (K1 i (Maybe a))) where   gSchema' _ _ = field (selName (undefined :: M1 S c f p)) False . schema . fmap (fromJust . unK1 . unM1) +-- TODO This instance does not correspond to the generic-aeson representation for Maybe instance Selector c => GJSONSCHEMA (M1 S c (K1 i (Maybe String))) where   gSchema' _ _ _ = field (selName (undefined :: M1 S c f p)) False $ Value 0 (-1)  instance (Selector c, GJSONSCHEMA f) => GJSONSCHEMA (M1 S c f) where-  gSchema' mc enm = field (selName (undefined :: M1 S c f p)) True . gSchema' mc enm . fmap unM1+  gSchema' mc enm = wrap . gSchema' mc enm . fmap unM1+    where+      wrap = case selName (undefined :: M1 S c f p) of+        "" -> id+        s -> field s True  multipleConstructors :: (Generic a, ConNames (Rep a)) => Proxy a -> Bool multipleConstructors = (> 1) . length . conNames . pv
src/Data/JSON/Schema/Types.hs view
@@ -1,11 +1,19 @@-{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}+{-# LANGUAGE+    FlexibleInstances+  , TypeSynonymInstances+  #-} -- | Types for defining JSON schemas. module Data.JSON.Schema.Types where  import Data.Maybe import Data.Proxy+import Data.String import Data.Text (Text)+import Data.Vector (Vector) import Data.Word (Word32)+import qualified Data.HashMap.Strict as H+import qualified Data.Map            as M+import qualified Data.Vector         as V  -- | A schema is any JSON value. type Schema = Value@@ -14,6 +22,7 @@ data Value =     Choice [Value] -- ^ A choice of multiple values, e.g. for sum types.   | Object [Field] -- ^ A JSON object.+  | Map    Value   -- ^ A JSON object with arbitrary keys.   | Array Int Int Bool Value -- ^ An array. The integers represent the                              -- lower and upper bound of the array                              -- size. The value -1 indicates no bound.@@ -28,6 +37,7 @@                     -- upper bound on the value. The value -1                     -- indicates no bound.   | Null+  | Any   deriving (Eq, Show)  -- | A field in an object.@@ -60,3 +70,12 @@  instance JSONSchema a => JSONSchema [a] where   schema = Array 0 (-1) False . schema . fmap head++instance JSONSchema a => JSONSchema (Vector a) where+  schema = Array 0 (-1) False . schema . fmap V.head++instance (IsString k, JSONSchema v) => JSONSchema (M.Map k v) where+  schema = Map . schema . fmap (head . M.elems)++instance (IsString k, JSONSchema v) => JSONSchema (H.HashMap k v) where+  schema = Map . schema . fmap (head . H.elems)