Skip to content

Commit

Permalink
Add FromJSON instances for Doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Feb 10, 2025
1 parent 49432a6 commit 97f56c8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions unison-share-api/src/Unison/Server/Doc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
module Unison.Server.Doc where

import Control.Monad
import Data.Aeson (ToJSON)
import Data.Aeson (ToJSON, FromJSON)
import Data.Foldable
import Data.Functor
import Data.Map qualified as Map
Expand Down Expand Up @@ -91,21 +91,21 @@ data DocG specialForm
| Column [(DocG specialForm)]
| Group (DocG specialForm)
deriving stock (Eq, Ord, Show, Generic, Functor, Foldable, Traversable)
deriving anyclass (ToJSON)
deriving anyclass (ToJSON, FromJSON)

deriving instance (ToSchema specialForm) => ToSchema (DocG specialForm)

type UnisonHash = Text

data Ref a = Term a | Type a
deriving stock (Eq, Ord, Show, Generic, Functor, Foldable, Traversable)
deriving anyclass (ToJSON)
deriving anyclass (ToJSON, FromJSON)

instance (ToSchema a) => ToSchema (Ref a)

data MediaSource = MediaSource {mediaSourceUrl :: Text, mediaSourceMimeType :: Maybe Text}
deriving stock (Eq, Ord, Show, Generic)
deriving anyclass (ToJSON, ToSchema)
deriving anyclass (ToJSON, FromJSON, ToSchema)

data RenderedSpecialForm
= Source [SrcRefs]
Expand All @@ -125,7 +125,7 @@ data RenderedSpecialForm
| Svg Text
| RenderError (RenderError SyntaxText)
deriving stock (Eq, Ord, Show, Generic)
deriving anyclass (ToJSON, ToSchema)
deriving anyclass (ToJSON, FromJSON, ToSchema)

data EvaluatedSpecialForm v
= ESource [(EvaluatedSrc v)]
Expand All @@ -151,7 +151,7 @@ data EvaluatedSpecialForm v
-- `Src folded unfolded`
data Src = Src SyntaxText SyntaxText
deriving stock (Eq, Ord, Show, Generic)
deriving anyclass (ToJSON, ToSchema)
deriving anyclass (ToJSON, FromJSON, ToSchema)

-- | Evaluate the doc, then render it.
evalAndRenderDoc ::
Expand Down Expand Up @@ -448,7 +448,7 @@ evalDoc terms typeOf eval types tm =
data RenderError trm
= InvalidTerm trm
deriving stock (Eq, Ord, Show, Generic)
deriving anyclass (ToJSON)
deriving anyclass (ToJSON, FromJSON)

deriving anyclass instance (ToSchema trm) => ToSchema (RenderError trm)

Expand Down

0 comments on commit 97f56c8

Please sign in to comment.