Skip to content

Commit

Permalink
Merge pull request #5254 from unisonweb/cp/defn-search-sync
Browse files Browse the repository at this point in the history
Add FromJSON for Display Object for definition search
  • Loading branch information
aryairani authored Jul 26, 2024
2 parents b12baa4 + a49146f commit f559576
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions unison-share-api/src/Unison/Server/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ instance (ToJSON b, ToJSON a) => ToJSON (DisplayObject b a) where
MissingObject sh -> object ["tag" Aeson..= String "MissingObject", "contents" Aeson..= sh]
UserObject a -> object ["tag" Aeson..= String "UserObject", "contents" Aeson..= a]

instance (FromJSON a, FromJSON b) => FromJSON (DisplayObject b a) where
parseJSON = withObject "DisplayObject" \o -> do
tag <- o .: "tag"
case tag of
"BuiltinObject" -> BuiltinObject <$> o .: "contents"
"MissingObject" -> MissingObject <$> o .: "contents"
"UserObject" -> UserObject <$> o .: "contents"
_ -> fail $ "Invalid tag: " <> Text.unpack tag

deriving instance (ToSchema b, ToSchema a) => ToSchema (DisplayObject b a)

-- [21/10/07] Hello, this is Mitchell. Name refactor in progress. Changing internal representation from a flat text to a
Expand Down

0 comments on commit f559576

Please sign in to comment.