packages feed

autodocodec-schema 0.1.0.5 → 0.2.0.0

raw patch · 3 files changed

+48/−16 lines, 3 filesdep +scientificdep ~autodocodecPVP ok

version bump matches the API change (PVP)

Dependencies added: scientific

Dependency ranges changed: autodocodec

API changes (from Hackage documentation)

+ Autodocodec.Schema: IntegerSchema :: !Bounds Integer -> JSONSchema
- Autodocodec.Schema: NumberSchema :: !Maybe NumberBounds -> JSONSchema
+ Autodocodec.Schema: NumberSchema :: !Bounds Scientific -> JSONSchema

Files

CHANGELOG.md view
@@ -1,5 +1,18 @@ # Changelog ++## [0.2.0.0] - 2024-07-26++* Support for `autodocodec >=0.4`.++### Added++* The `IntegerSchema` constructor++### Changed++* The `NumberSchema` now contains `Bounds Scientific`.+ ## [0.1.0.4] - 2024-06-23  ### Added
autodocodec-schema.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           autodocodec-schema-version:        0.1.0.5+version:        0.2.0.0 synopsis:       Autodocodec interpreters for JSON Schema homepage:       https://github.com/NorfairKing/autodocodec#readme bug-reports:    https://github.com/NorfairKing/autodocodec/issues@@ -32,10 +32,11 @@       src   build-depends:       aeson-    , autodocodec >=0.3.0.0+    , autodocodec >=0.4.0.0     , base >=4.7 && <5     , containers     , mtl+    , scientific     , text     , unordered-containers     , validity
src/Autodocodec/Schema.hs view
@@ -22,6 +22,8 @@ import qualified Data.List.NonEmpty as NE import Data.Map (Map) import qualified Data.Map as M+import Data.Maybe+import Data.Scientific import Data.Set (Set) import qualified Data.Set as S import Data.Text (Text)@@ -44,7 +46,8 @@   | NullSchema   | BoolSchema   | StringSchema-  | NumberSchema !(Maybe NumberBounds)+  | IntegerSchema !(Bounds Integer)+  | NumberSchema !(Bounds Scientific)   | ArraySchema !JSONSchema   | MapSchema !JSONSchema   | -- | This needs to be a list because keys should stay in their original ordering.@@ -79,10 +82,18 @@         NullSchema -> ["type" JSON..= ("null" :: Text)]         BoolSchema -> ["type" JSON..= ("boolean" :: Text)]         StringSchema -> ["type" JSON..= ("string" :: Text)]-        NumberSchema mBounds ->-          ("type" JSON..= ("number" :: Text)) : case mBounds of-            Nothing -> []-            Just NumberBounds {..} -> ["minimum" JSON..= numberBoundsLower, "maximum" JSON..= numberBoundsUpper]+        IntegerSchema Bounds {..} ->+          catMaybes+            [ Just ("type" JSON..= ("integer" :: Text)),+              ("minimum" JSON..=) <$> boundsLower,+              ("maximum" JSON..=) <$> boundsUpper+            ]+        NumberSchema Bounds {..} ->+          catMaybes+            [ Just ("type" JSON..= ("number" :: Text)),+              ("minimum" JSON..=) <$> boundsLower,+              ("maximum" JSON..=) <$> boundsUpper+            ]         ArraySchema s ->           let itemSchemaVal = go s            in ["type" JSON..= ("array" :: Text), ("items", JSON.object itemSchemaVal)]@@ -123,13 +134,14 @@       Just "null" -> pure NullSchema       Just "boolean" -> pure BoolSchema       Just "string" -> pure StringSchema+      Just "integer" -> do+        boundsLower <- o JSON..:? "minimum"+        boundsUpper <- o JSON..:? "maximum"+        pure $ IntegerSchema Bounds {..}       Just "number" -> do-        mLower <- o JSON..:? "minimum"-        mUpper <- o JSON..:? "maximum"-        pure $-          NumberSchema $ case (,) <$> mLower <*> mUpper of-            Nothing -> Nothing-            Just (numberBoundsLower, numberBoundsUpper) -> Just NumberBounds {..}+        boundsLower <- o JSON..:? "minimum"+        boundsUpper <- o JSON..:? "maximum"+        pure $ NumberSchema Bounds {..}       Just "array" -> do         mI <- o JSON..:? "items"         case mI of@@ -159,7 +171,7 @@                         Just name -> RefSchema name                         Nothing -> AnySchema                       Nothing -> AnySchema-      t -> fail $ "unknown schema type:" <> show t+      t -> fail $ "unknown schema type: " <> show t  data ObjectSchema   = ObjectKeySchema !Text !KeyRequirement !JSONSchema !(Maybe Text)@@ -274,11 +286,16 @@       StringSchema -> pure $ case value of         JSON.String _ -> True         _ -> False-      NumberSchema mBounds -> pure $ case value of-        JSON.Number s -> case maybe Right checkNumberBounds mBounds s of+      IntegerSchema bounds -> pure $ case value of+        JSON.Number s -> case checkBounds (fromInteger <$> bounds) s of           Left _ -> False           Right _ -> True         _ -> False+      NumberSchema bounds -> pure $ case value of+        JSON.Number s -> case checkBounds bounds s of+          Left _ -> False+          Right _ -> True+        _ -> False       ArraySchema as -> case value of         JSON.Array v -> and <$> mapM (`go` as) v         _ -> pure False@@ -319,6 +336,7 @@       NullCodec -> pure NullSchema       BoolCodec mname -> pure $ maybe id CommentSchema mname BoolSchema       StringCodec mname -> pure $ maybe id CommentSchema mname StringSchema+      IntegerCodec mname mBounds -> pure $ maybe id CommentSchema mname $ IntegerSchema mBounds       NumberCodec mname mBounds -> pure $ maybe id CommentSchema mname $ NumberSchema mBounds       ArrayOfCodec mname c -> do         s <- go c