Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roundtrip YAML decode/encode before processing schema to support YAML anchor aliaes #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion domain.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ library
template-haskell-compat-v0208 >=0.1.5 && <0.2,
text >=1.2.3 && <2,
th-lego >=0.2.3 && <0.3,
yaml-unscrambler >=0.1 && <0.2
yaml-unscrambler >=0.1 && <0.2,
yaml >=0.11.5 && <0.12

test-suite loading-demo
type: exitcode-stdio-1.0
Expand Down
9 changes: 6 additions & 3 deletions library/Domain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ import Domain.Prelude hiding (liftEither, readFile, lift)
import Language.Haskell.TH.Syntax
import Language.Haskell.TH.Quote
import qualified Data.ByteString as ByteString
import qualified Data.Yaml as Yaml
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified Domain.Resolvers.TypeCentricDoc as TypeCentricResolver
import qualified Domain.TH.TypeDec as TypeDec
Expand Down Expand Up @@ -231,8 +233,8 @@ readFile :: FilePath -> Q ByteString
readFile path =
do
addDependentFile path
readRes <- liftIO (tryIOError (ByteString.readFile path))
liftEither (first showAsText readRes)
readRes <- liftIO $ Yaml.decodeFileEither path
liftEither $ bimap (Text.pack . displayException) (Yaml.encode @Yaml.Value) readRes

parseString :: String -> Q Schema
parseString =
Expand All @@ -245,7 +247,8 @@ parseText =
parseByteString :: ByteString -> Q Schema
parseByteString input =
liftEither $ do
doc <- YamlUnscrambler.parseByteString TypeCentricYaml.doc input
value :: Yaml.Value <- first (Text.pack . displayException) (Yaml.decodeEither' input)
doc <- YamlUnscrambler.parseByteString TypeCentricYaml.doc (Yaml.encode value)
decs <- TypeCentricResolver.eliminateDoc doc
return (Schema decs)

Expand Down