Skip to content

Commit

Permalink
Merge pull request #10 from kanmu/hidetatz/fix-prop-sort
Browse files Browse the repository at this point in the history
bug: sort inline properties recusively to prevent flaky struct field order
  • Loading branch information
hidetatz authored Oct 1, 2024
2 parents de81375 + 5fd8e8d commit 191dee3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ func sortProperties(props []*Property) []*Property {
for _, n := range names {
sorted = append(sorted, pMap[n])
}

// In case the top level property contains another property internally,
// sort them recursively.
for _, p := range sorted {
if p.InlineProperties != nil {
p.InlineProperties = sortProperties(p.InlineProperties)
}
}

return sorted
}

Expand Down Expand Up @@ -252,7 +261,6 @@ func (p *Parser) ParseResources() (map[string]Resource, error) {
if err != nil {
return nil, errors.Wrapf(err, "failed to parse %s", id)
}
fld.InlineProperties = sortProperties(fld.InlineProperties)
flds = append(flds, fld)
}
rs.Properties = sortProperties(flds)
Expand Down

0 comments on commit 191dee3

Please sign in to comment.