diff options
author | Kierán Meinhardt <kmein@posteo.de> | 2024-10-12 11:19:20 +0200 |
---|---|---|
committer | Kierán Meinhardt <kmein@posteo.de> | 2024-10-12 11:19:20 +0200 |
commit | 1e1f0daa077eaf73382c09b06456947e8a9dc204 (patch) | |
tree | 9c6607f0773572e8080de01de3b9472067b3a9f2 /backend/app/Main.hs | |
parent | b3327fec742b1fd93c6fd0bd0bfc3f4775bf58f8 (diff) |
correct json schema syntax for optional types and references
Diffstat (limited to 'backend/app/Main.hs')
-rw-r--r-- | backend/app/Main.hs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/backend/app/Main.hs b/backend/app/Main.hs index 47dc41a..063bb1a 100644 --- a/backend/app/Main.hs +++ b/backend/app/Main.hs @@ -108,12 +108,16 @@ fromAutoTypes path (U.Object ps) = ("$id", J.toJSON @String (path <> ".schema.json")), ("title", J.toJSON @String path), ("type", J.toJSON @String "object"), - ("properties", J.toJSON (M.map toProperty ps)) + ("properties", J.toJSON (M.map toProperty ps)), + ("required", J.toJSON (M.keys (M.filter isRequired ps))) ] where - toProperty (U.Scalar "string") = "string" :: String - toProperty (U.Option (Just (U.Scalar "string"))) = "string?" :: String - toProperty (U.Reference i) = "$ref:" <> i + isRequired (U.Option _) = False + isRequired _ = True + toProperty :: U.T -> M.Map String String + toProperty (U.Scalar "string") = M.fromList [("type", "string")] + toProperty (U.Option (Just (U.Scalar "string"))) = M.fromList [("type", "string")] + toProperty (U.Reference i) = M.fromList [("$ref", i)] toProperty x = error ("unhandled type: " <> show x) fromAutoTypes _ _ = error "Only JSON objects are supported." |