From bf2e9da9a27c470b1da0c548f770b86f5c67626b Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Tue, 3 Feb 2026 13:33:31 +0100 Subject: [PATCH] Improve documentation for anyOf with lists in them --- src/SchemaUtils.elm | 50 +++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/SchemaUtils.elm b/src/SchemaUtils.elm index d9f0417..7849180 100644 --- a/src/SchemaUtils.elm +++ b/src/SchemaUtils.elm @@ -226,22 +226,8 @@ schemaToType seen schema = Json.Schema.Definitions.ItemDefinition itemSchema -> CliMonad.map - (\{ type_, documentation } -> - { type_ = Common.List type_ - , documentation = - [ subSchema.description - , Maybe.map - (\doc -> - if String.contains "\n" doc then - "A list of:\n" ++ doc - - else - "A list of: " ++ doc - ) - documentation - ] - |> joinIfNotEmpty "\n\n" - } + (\item -> + toListType subSchema.description item ) (schemaToType seen itemSchema) @@ -259,12 +245,7 @@ schemaToType seen schema = case areAllArrays schemas of Just innerSchemas -> oneOfToType innerSchemas - |> CliMonad.map - (\t -> - { type_ = Common.List t.type_ - , documentation = t.documentation - } - ) + |> CliMonad.map (toListType subSchema.description) Nothing -> let @@ -507,6 +488,31 @@ schemaToType seen schema = ) +toListType : + Maybe String + -> + { type_ : Common.Type + , documentation : Maybe String + } + -> { type_ : Common.Type, documentation : Maybe String } +toListType description { type_, documentation } = + { type_ = Common.List type_ + , documentation = + [ description + , Maybe.map + (\doc -> + if String.contains "\n" doc then + "A list of:\n" ++ doc + + else + "A list of: " ++ doc + ) + documentation + ] + |> joinIfNotEmpty "\n\n" + } + + areAllArrays : List Json.Schema.Definitions.Schema -> Maybe (List Json.Schema.Definitions.Schema) areAllArrays schemas = schemas