From 54eeb93257267e3c0bce5d7327bb20b31ba8ca32 Mon Sep 17 00:00:00 2001 From: Matthew Christopher Date: Wed, 7 Jul 2021 11:55:27 -0700 Subject: [PATCH 1/2] Improve flattening warning --- hack/generator/pkg/codegen/pipeline/flatten_properties.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hack/generator/pkg/codegen/pipeline/flatten_properties.go b/hack/generator/pkg/codegen/pipeline/flatten_properties.go index 57db9d18021..e9f522842f5 100644 --- a/hack/generator/pkg/codegen/pipeline/flatten_properties.go +++ b/hack/generator/pkg/codegen/pipeline/flatten_properties.go @@ -39,6 +39,8 @@ func applyPropertyFlattening( func makeFlatteningVisitor(defs astmodel.Types) astmodel.TypeVisitor { return astmodel.TypeVisitorBuilder{ VisitObjectType: func(this *astmodel.TypeVisitor, it *astmodel.ObjectType, ctx interface{}) (astmodel.Type, error) { + name := ctx.(astmodel.TypeName) + newIt, err := astmodel.IdentityVisitOfObjectType(this, it, ctx) if err != nil { return nil, err @@ -53,7 +55,7 @@ func makeFlatteningVisitor(defs astmodel.Types) astmodel.TypeVisitor { // safety check: if err := checkForDuplicateNames(newProps); err != nil { - klog.Warningf("Flattening caused duplicate property names, skipping flattening: %s", err) + klog.Warningf("Skipping flattening for %s: %s", name, err) return it, nil // nolint:nilerr } From c20770a8b295ca6811eb5d310dd35b47c865b1a6 Mon Sep 17 00:00:00 2001 From: Matthew Christopher Date: Wed, 7 Jul 2021 12:02:36 -0700 Subject: [PATCH 2/2] Add debug log to flattening --- hack/generator/pkg/codegen/pipeline/flatten_properties.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hack/generator/pkg/codegen/pipeline/flatten_properties.go b/hack/generator/pkg/codegen/pipeline/flatten_properties.go index e9f522842f5..05faa279ef2 100644 --- a/hack/generator/pkg/codegen/pipeline/flatten_properties.go +++ b/hack/generator/pkg/codegen/pipeline/flatten_properties.go @@ -59,6 +59,10 @@ func makeFlatteningVisitor(defs astmodel.Types) astmodel.TypeVisitor { return it, nil // nolint:nilerr } + if len(newProps) != len(it.Properties()) { + klog.V(4).Infof("Flattened properties in %s", name) + } + result := it.WithoutProperties().WithProperties(newProps...) return result, nil