From a82fc102b4c495b12440bb70f42a2c0d089f8b11 Mon Sep 17 00:00:00 2001 From: Hidetatz Yaginuma Date: Tue, 1 Oct 2024 11:12:31 +0900 Subject: [PATCH 1/2] sort inline properties recusively to prevente flaky struct field order --- parser.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/parser.go b/parser.go index ac23da2..c70b5d0 100644 --- a/parser.go +++ b/parser.go @@ -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 } From 5fd8e8d8293b5fbad7de7bfeb176a6bbcb80bff4 Mon Sep 17 00:00:00 2001 From: Hidetatz Yaginuma Date: Tue, 1 Oct 2024 13:22:51 +0900 Subject: [PATCH 2/2] remove duplicated line --- parser.go | 1 - 1 file changed, 1 deletion(-) diff --git a/parser.go b/parser.go index c70b5d0..62f5882 100644 --- a/parser.go +++ b/parser.go @@ -261,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)