autodocodec-yaml 0.0.0.0 → 0.1.0.0
raw patch · 4 files changed
+39/−15 lines, 4 filesdep ~autodocodec-schema
Dependency ranges changed: autodocodec-schema
Files
- CHANGELOG.md +7/−0
- autodocodec-yaml.cabal +3/−3
- src/Autodocodec/Yaml/Encode.hs +2/−2
- src/Autodocodec/Yaml/Schema.hs +27/−10
CHANGELOG.md view
@@ -1,5 +1,12 @@ # Changelog +## [0.1.0.0] - 2021-12-23++### Changed++* Support for `autodocodec-schema >=0.1.0.0` with comments for `anyOf` and `oneOf`.+* Added special support for 'or null'.+ ## [0.0.0.0] - 2021-11-19 First release.
autodocodec-yaml.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.4.+-- This file has been generated from package.yaml by hpack version 0.34.5. -- -- see: https://github.com/sol/hpack name: autodocodec-yaml-version: 0.0.0.0+version: 0.1.0.0 synopsis: Autodocodec interpreters for yaml homepage: https://github.com/NorfairKing/autodocodec#readme bug-reports: https://github.com/NorfairKing/autodocodec/issues@@ -35,7 +35,7 @@ src build-depends: autodocodec- , autodocodec-schema+ , autodocodec-schema >=0.1.0.0 , base >=4.7 && <5 , bytestring , containers
src/Autodocodec/Yaml/Encode.hs view
@@ -42,7 +42,7 @@ ValueCodec -> yamlValue (a :: JSON.Value) EqCodec value c -> go value c BimapCodec _ g c -> go (g a) c- EitherCodec c1 c2 -> case (a :: Either _ _) of+ EitherCodec _ c1 c2 -> case (a :: Either _ _) of Left a1 -> go a1 c1 Right a2 -> go a2 c2 CommentCodec _ c -> go a c@@ -60,7 +60,7 @@ then [] else goObject a (OptionalKeyWithDefaultCodec k c defaultValue mDoc) BimapCodec _ g c -> goObject (g a) c- EitherCodec c1 c2 -> case (a :: Either _ _) of+ EitherCodec _ c1 c2 -> case (a :: Either _ _) of Left a1 -> goObject a1 c1 Right a2 -> goObject a2 c2 PureCodec _ -> []
src/Autodocodec/Yaml/Schema.hs view
@@ -63,6 +63,23 @@ docToLines :: Text -> [[Chunk]] docToLines doc = map (\line -> [chunk "# ", chunk line]) (T.lines doc) + choiceChunks :: NonEmpty [[Chunk]] -> [[Chunk]]+ choiceChunks = \case+ chunks :| [] -> addInFrontOfFirstInList ["[ "] chunks ++ [["]"]]+ (chunks :| restChunks) ->+ concat $+ addInFrontOfFirstInList ["[ "] chunks :+ map (addInFrontOfFirstInList [", "]) restChunks ++ [[["]"]]]++ anyOfChunks :: NonEmpty [[Chunk]] -> [[Chunk]]+ anyOfChunks = (["# ", fore green "any of"] :) . choiceChunks++ oneOfChunks :: NonEmpty [[Chunk]] -> [[Chunk]]+ oneOfChunks = (["# ", fore green "one of"] :) . choiceChunks++ orNullChunks :: JSONSchema -> [[Chunk]]+ orNullChunks = (["# ", fore green "or null"] :) . go+ go :: JSONSchema -> [[Chunk]] go = \case AnySchema -> [[fore yellow "<any>"]]@@ -90,20 +107,19 @@ addInFrontOfFirstInList [fore white "<key>", ": "] $ [] : go s ObjectSchema os -> goObject os ValueSchema v -> [[jsonValueChunk v]]- ChoiceSchema ne -> choiceChunks $ NE.map go ne+ AnyOfSchema ne -> case ne of+ (NullSchema :| [s]) -> orNullChunks s+ (s :| [NullSchema]) -> orNullChunks s+ _ -> anyOfChunks $ NE.map go ne+ OneOfSchema ne -> case ne of+ (NullSchema :| [s]) -> orNullChunks s+ (s :| [NullSchema]) -> orNullChunks s+ _ -> oneOfChunks $ NE.map go ne CommentSchema comment s -> docToLines comment ++ go s RefSchema name -> [[fore cyan $ chunk $ "ref: " <> name]] WithDefSchema defs (RefSchema _) -> concatMap (\(name, s') -> [fore cyan $ chunk $ "def: " <> name] : go s') (M.toList defs) WithDefSchema defs s -> concatMap (\(name, s') -> [fore cyan $ chunk $ "def: " <> name] : go s') (M.toList defs) ++ go s - choiceChunks :: NonEmpty [[Chunk]] -> [[Chunk]]- choiceChunks = \case- chunks :| [] -> addInFrontOfFirstInList ["[ "] chunks ++ [["]"]]- (chunks :| restChunks) ->- concat $- addInFrontOfFirstInList ["[ "] chunks :- map (addInFrontOfFirstInList [", "]) restChunks ++ [[["]"]]]- goObject :: ObjectSchema -> [[Chunk]] goObject = \case ObjectAnySchema -> [["<object>"]]@@ -121,4 +137,5 @@ prefixLines = ["# ", requirementComment kr] : defaultValueLine ++ maybe [] docToLines mdoc in addInFrontOfFirstInList [fore white $ chunk k, ": "] (prefixLines ++ keySchemaChunks) ObjectAllOfSchema ne -> concatMap goObject $ NE.toList ne- ObjectChoiceSchema ne -> choiceChunks $ NE.map goObject ne+ ObjectAnyOfSchema ne -> anyOfChunks $ NE.map goObject ne+ ObjectOneOfSchema ne -> oneOfChunks $ NE.map goObject ne