Skip to content
Merged
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
50 changes: 28 additions & 22 deletions src/SchemaUtils.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down