Skip to content

Commit

Permalink
Merge pull request #101 from losisin/fix/merge-items-from-nested-arrays
Browse files Browse the repository at this point in the history
feature: merge nested arrays
  • Loading branch information
losisin authored Nov 11, 2024
2 parents e45ac01 + 74bdd3b commit aed914b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,20 @@ func parseNode(keyNode *yaml.Node, valNode *yaml.Node) (*Schema, bool) {

case yaml.SequenceNode:
schema.Type = "array"
if len(valNode.Content) > 0 {
itemSchema, _ := parseNode(nil, valNode.Content[0])

mergedItemSchema := &Schema{}

for _, itemNode := range valNode.Content {
itemSchema, _ := parseNode(nil, itemNode)
if itemSchema != nil && !itemSchema.Hidden {
schema.Items = itemSchema
mergedItemSchema = mergeSchemas(mergedItemSchema, itemSchema)
}
}

if mergedItemSchema != nil {
schema.Items = mergedItemSchema
}

case yaml.ScalarNode:
if valNode.Style == yaml.DoubleQuotedStyle || valNode.Style == yaml.SingleQuotedStyle {
schema.Type = "string"
Expand Down

0 comments on commit aed914b

Please sign in to comment.