Skip to content

Commit

Permalink
fix schema renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed May 5, 2024
1 parent e39255f commit 4cc27dc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/doc/Swarm/Doc/Schema/Refined.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ getSchemaReferences = \case
Alternatives xs -> concatMap getSchemaReferences xs
Reference x -> pure x
ListOf x -> getSchemaReferences x
EnumList _ -> []

-- | A subset of all JSON schemas, conforming to internal Swarm conventions.
--
Expand Down
2 changes: 2 additions & 0 deletions app/doc/Swarm/Doc/Schema/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Data.Text qualified as T
import Data.Text.IO qualified as TIO
import Data.Vector qualified as V
import Swarm.Doc.Schema.Arrangement
import Data.List.NonEmpty qualified as NE
import Swarm.Doc.Schema.Parse
import Swarm.Doc.Schema.Refined
import Swarm.Doc.Schema.SchemaType
Expand Down Expand Up @@ -176,6 +177,7 @@ listToText titleMap = \case
Alternatives xs -> renderAlternatives $ map (listToText titleMap) xs
Reference r@(SchemaIdReference x) -> schemaLink r x
ListOf x -> listToText titleMap x <> text " list"
EnumList xs -> renderAlternatives $ NE.toList $ text <$> xs
where
renderAlternatives = mconcat . intersperse (text " or ")
schemaLink r = link (fragmentHref titleMap r) "Link to object properties" . text
Expand Down
2 changes: 2 additions & 0 deletions app/doc/Swarm/Doc/Schema/SchemaType.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Data.Aeson
import Data.Text (Text)
import Data.Text qualified as T
import System.FilePath (takeBaseName)
import Data.List.NonEmpty (NonEmpty)

newtype SingleOrList a = SingleOrList
{ getList :: [a]
Expand All @@ -29,6 +30,7 @@ data SchemaType
Reference SchemaIdReference
| -- | Members of a list, all of the given schema type
ListOf SchemaType
| EnumList (NonEmpty Text)
deriving (Eq, Ord, Show)

newtype SchemaIdReference = SchemaIdReference Text
Expand Down

0 comments on commit 4cc27dc

Please sign in to comment.