aboutsummaryrefslogtreecommitdiffstats
path: root/autotypes/src
diff options
context:
space:
mode:
authorLibravatar Kierán Meinhardt <kmein@posteo.de>2024-10-12 12:36:42 +0200
committerLibravatar Kierán Meinhardt <kmein@posteo.de>2024-10-12 12:36:42 +0200
commit47160b1fa5a9b351a999f5ca033dc165435af70e (patch)
treef9685ebf55b5ac5eafc422a946a4b1e1f82053a5 /autotypes/src
parent0878de24223e51adfc91ea3a2a8e8f2cdc21debb (diff)
autotypes schema toString via aeson
Diffstat (limited to 'autotypes/src')
-rw-r--r--autotypes/src/AutoTypes/Unify.hs19
1 files changed, 3 insertions, 16 deletions
diff --git a/autotypes/src/AutoTypes/Unify.hs b/autotypes/src/AutoTypes/Unify.hs
index 2abde6a..bfbd05b 100644
--- a/autotypes/src/AutoTypes/Unify.hs
+++ b/autotypes/src/AutoTypes/Unify.hs
@@ -13,8 +13,10 @@ where
import Control.Arrow
import Control.Exception (Exception, throw)
import qualified Data.Aeson as A
+import qualified Data.Aeson.Encode.Pretty as A
import qualified Data.Aeson.Key as K
import qualified Data.Aeson.KeyMap as KM
+import qualified Data.ByteString.Lazy.Char8 as BL
import Data.Aeson.QQ
import Data.List (intercalate, nub)
import Data.Map (Map)
@@ -63,22 +65,7 @@ instance A.ToJSON T where
toJSON (Reference i) = A.object [K.fromString "$ref" A..= A.String (T.pack i)]
toString :: T -> String
-toString = intercalate "\n" . map (\(n, s) -> indent n s) . toString_ 0
-
-toString_ :: Int -> T -> [(Int, String)]
-toString_ n (Object kvs) =
- concat
- [ [(n, "{")],
- concat . M.elems $
- M.mapWithKey (\s t -> (n + 1, s) : toString_ (n + 2) t) kvs,
- [(n, "}")]
- ]
-toString_ n (Scalar s) = [(n, scalarTypeString s)]
-toString_ n (Union ts) = concatMap (toString_ n) ts
-toString_ n (Option Nothing) = [(n, "null")]
-toString_ n (Option (Just t)) = map (second (++ "?")) (toString_ n t)
-
-indent n = (++) (replicate (4 * n) ' ')
+toString = BL.unpack . A.encodePretty . A.toJSON
union :: S.Set T -> T
union ts