json-schema 0.7.2.0 → 0.7.3.0
raw patch · 3 files changed
+42/−3 lines, 3 files
Files
- CHANGELOG.md +4/−0
- json-schema.cabal +1/−1
- src/Data/JSON/Schema/Types.hs +37/−2
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Changelog +### 0.7.3.0++* Add `JSONSchema` instances for all standard Num types and Scientific.+ ### 0.7.2.0 * Add `JSONSchema` instances for Double, Float, Fixed
json-schema.cabal view
@@ -1,5 +1,5 @@ name: json-schema-version: 0.7.2.0+version: 0.7.3.0 synopsis: Types and type classes for defining JSON schemas. description: Types and type classes for defining JSON schemas. .
src/Data/JSON/Schema/Types.hs view
@@ -2,6 +2,7 @@ FlexibleInstances , OverloadedStrings , TypeSynonymInstances+ , ScopedTypeVariables #-} -- | Types for defining JSON schemas. module Data.JSON.Schema.Types@@ -15,13 +16,15 @@ ) where import Data.Fixed+import Data.Int import Data.Maybe import Data.Proxy+import Data.Scientific import Data.String import Data.Text (Text) import Data.Time.Clock (UTCTime) import Data.Vector (Vector)-import Data.Word (Word32)+import Data.Word import qualified Data.Aeson.Types as Aeson import qualified Data.HashMap.Strict as H import qualified Data.Map as M@@ -68,6 +71,11 @@ unbounded :: Bound unbounded = Bound Nothing Nothing +integralSchema :: forall a. (Bounded a, Integral a) => Proxy a -> Schema+integralSchema _ =+ Number $ Bound (Just $ fromIntegral (minBound::a))+ (Just $ fromIntegral (maxBound::a))+ unboundedLength :: LengthBound unboundedLength = LengthBound Nothing Nothing @@ -87,9 +95,33 @@ instance JSONSchema Integer where schema _ = Number unbounded -instance JSONSchema Word32 where+instance JSONSchema Int8 where+ schema = integralSchema++instance JSONSchema Int16 where+ schema = integralSchema++instance JSONSchema Int32 where schema _ = Number unbounded +instance JSONSchema Int64 where+ schema _ = Number unbounded++instance JSONSchema Word where+ schema _ = Number (Bound (Just 0) Nothing)++instance JSONSchema Word8 where+ schema = integralSchema++instance JSONSchema Word16 where+ schema = integralSchema++instance JSONSchema Word32 where+ schema _ = Number (Bound (Just 0) Nothing)++instance JSONSchema Word64 where+ schema _ = Number (Bound (Just 0) Nothing)+ instance JSONSchema Float where schema _ = Number unbounded @@ -97,6 +129,9 @@ schema _ = Number unbounded instance HasResolution a => JSONSchema (Fixed a) where+ schema _ = Number unbounded++instance JSONSchema Scientific where schema _ = Number unbounded instance JSONSchema Bool where