packages feed

autodocodec-yaml 0.1.0.0 → 0.1.0.1

raw patch · 4 files changed

+17/−7 lines, 4 files

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Changelog +## [0.1.0.1] - 2022-04-26++### Added++* Compatibility with `aeson >= 2.0.0.0`+ ## [0.1.0.0] - 2021-12-23  ### Changed
autodocodec-yaml.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           autodocodec-yaml-version:        0.1.0.0+version:        0.1.0.1 synopsis:       Autodocodec interpreters for yaml homepage:       https://github.com/NorfairKing/autodocodec#readme bug-reports:    https://github.com/NorfairKing/autodocodec/issues
src/Autodocodec/Yaml/Encode.hs view
@@ -6,11 +6,12 @@  module Autodocodec.Yaml.Encode where +import qualified Autodocodec.Aeson.Compat as Compat import Autodocodec.Aeson.Encode import Autodocodec.Class import Autodocodec.Codec import Autodocodec.DerivingVia-import qualified Data.HashMap.Strict as HM+import Control.Arrow (first) import Data.Scientific import Data.Text (Text) import qualified Data.Text as T@@ -75,7 +76,7 @@      -- Encode a 'JSON.Object'     yamlObject :: JSON.Object -> YamlBuilder-    yamlObject a = Yaml.mapping $ HM.toList (HM.map yamlValue (a :: JSON.Object))+    yamlObject a = Yaml.mapping $ map (first Compat.fromKey) $ Compat.toList (Compat.map yamlValue (a :: JSON.Object))      -- Encode a 'JSON.Value'     yamlValue :: JSON.Value -> YamlBuilder
src/Autodocodec/Yaml/Schema.hs view
@@ -57,8 +57,8 @@       [] -> [cs] -- Shouldn't happen, but fine if it doesn't       (l : ls) -> (cs ++ l) : indent ls -    jsonValueChunk :: Yaml.Value -> Chunk-    jsonValueChunk v = chunk $ T.strip $ TE.decodeUtf8With TE.lenientDecode (Yaml.encode v)+    jsonValueChunks :: Yaml.Value -> [[Chunk]]+    jsonValueChunks v = map ((: []) . chunk) $ T.lines $ T.strip $ TE.decodeUtf8With TE.lenientDecode (Yaml.encode v)      docToLines :: Text -> [[Chunk]]     docToLines doc = map (\line -> [chunk "# ", chunk line]) (T.lines doc)@@ -106,7 +106,7 @@       MapSchema s ->         addInFrontOfFirstInList [fore white "<key>", ": "] $ [] : go s       ObjectSchema os -> goObject os-      ValueSchema v -> [[jsonValueChunk v]]+      ValueSchema v -> jsonValueChunks v       AnyOfSchema ne -> case ne of         (NullSchema :| [s]) -> orNullChunks s         (s :| [NullSchema]) -> orNullChunks s@@ -133,7 +133,10 @@          in let keySchemaChunks = go ks                 defaultValueLine = case mDefaultValue kr of                   Nothing -> []-                  Just defaultValue -> [[chunk "# default: ", fore magenta $ jsonValueChunk defaultValue]]+                  Just defaultValue ->+                    case jsonValueChunks defaultValue of+                      [c] -> [chunk "# default: " : map (fore magenta) c]+                      cs -> [chunk "# default: "] : map ((chunk "#   " :) . map (fore magenta)) cs                 prefixLines = ["# ", requirementComment kr] : defaultValueLine ++ maybe [] docToLines mdoc              in addInFrontOfFirstInList [fore white $ chunk k, ": "] (prefixLines ++ keySchemaChunks)       ObjectAllOfSchema ne -> concatMap goObject $ NE.toList ne