Fix nondeterministic NonNamespaced annotations in register generator#10
Conversation
📝 WalkthroughWalkthroughThese changes refactor how non-namespaced status is determined and communicated in API code generation. The parsing logic now unconditionally computes non-namespaced status for all types, while template generation restricts the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Two bugs caused nondeterministic NonNamespaced annotations in generated register files: 1. parse.go gated NonNamespaced detection behind next.Resource != nil, but types can be encountered first as subtypes (Resource=nil) via map iteration. Since processed types are skipped on re-encounter, the Resource version never runs, leaving NonNamespaced=false. 2. The template unconditionally emitted "// +genclient" on one line, then conditionally emitted "// +genclient:nonNamespaced" or a duplicate "// +genclient" on the next. Now the second line only emits when NonNamespaced is true.
ad09207 to
6ab2d5b
Compare
Summary
next.Resource != nilgate on NonNamespaced detection inparse.go. Types encountered first as subtypes (via map iteration with nondeterministic order) hadResource=nil, causing NonNamespaced to remainfalseeven for nonNamespaced resources.// +genclient:nonNamespacedwhen NonNamespaced is true, instead of emitting a duplicate// +genclientline when false.Summary by CodeRabbit