From b1a4822d5954fe02b82f2c525403c74b3920befe Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 6 Jun 2024 22:42:44 +0200 Subject: support optional fields --- frontend/app/Schema.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'frontend/app/Schema.hs') diff --git a/frontend/app/Schema.hs b/frontend/app/Schema.hs index 0530061..1a52f52 100644 --- a/frontend/app/Schema.hs +++ b/frontend/app/Schema.hs @@ -115,12 +115,15 @@ schemaForm schema = "string" -> A.Object . AM.singleton k <$> ( F.mapValues (getO k) (setO k) $ - jsonString (AK.toString k) + fmap A.String . F.mapValues fromJson toJson $ + F.input (AK.toString k) ) "string?" -> A.Object . AM.singleton k - <$> ( F.mapValues (getO k) (setO k) $ - jsonString (AK.toString k) + <$> ( F.mapValues (getO k) (setO k) + $ fmap (maybe A.Null A.String) + . F.mapValues fromJson toJson + $ F.optional (F.input (AK.toString k)) ) ) <$> (M.toList properties) @@ -143,6 +146,3 @@ getO k (A.Object kvs) = fromMaybe A.Null (AM.lookup k kvs) setO :: AK.Key -> A.Value -> A.Value -> A.Value setO k v (A.Object kvs) = A.Object (AM.insert k v kvs) - -jsonString :: String -> F.Form A.Value A.Value -jsonString = fmap A.String . F.mapValues fromJson toJson . F.string -- cgit v1.2.3