diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-06-06 22:42:44 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-06-06 22:42:44 +0200 |
commit | b1a4822d5954fe02b82f2c525403c74b3920befe (patch) | |
tree | 6a284f7ec64dd0bb3bc7ff3e1812139b3a2f3932 /frontend/app/Schema.hs | |
parent | 612da78d17c575cd5ade1de62dc1a3c514129de0 (diff) |
support optional fields
Diffstat (limited to 'frontend/app/Schema.hs')
-rw-r--r-- | frontend/app/Schema.hs | 12 |
1 files changed, 6 insertions, 6 deletions
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 |