diff --git a/src/Language/Json/Type.hs b/src/Language/Json/Type.hs index 2df689a..023c325 100644 --- a/src/Language/Json/Type.hs +++ b/src/Language/Json/Type.hs @@ -85,6 +85,8 @@ isObject = \case Object _ -> True _ -> False +-- | Find the type of a value. + infer :: Json.Value -> Type infer = \case Value.Null -> Null @@ -107,6 +109,8 @@ instance HasField "actual" Mismatch Type where getField :: Mismatch -> Type getField = (.inferred) +-- | Compute all the differences to the expected type. Empty List means that the value is conforming. + conforms :: Type -> Json.Value -> [Mismatch] conforms = conforms' [] @@ -135,6 +139,8 @@ conforms' path layout value = case (value, layout) of else Foldable.concatMap id mismatches _ -> pure $ Mismatch {expected=layout, inferred=infer value, value=value, path=path} +-- | Choose any arbitrary value conforming to the type. + sample :: Type -> Gen Value sample = \case All -> arbitrary