Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new codegen utility to “flatten” Go API model structs into decode-efficient equivalents by replacing nested/complex field types with map[string]any, plus a cmd/flatten CLI wrapper for go:generate usage.
Changes:
- Introduces
structs.Flattengenerator, type-resolution logic, options, and Go template for emitting flattened structs. - Adds a
cmd/flattenCLI to drive generation from flags (-source,-from,-to,-output,-package,-sort,-extra). - Adds snapshot-based tests + testdata covering base behavior, multiple structs, extra fields, extra scalars, and sorting.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
structs/flatten.go |
Core generator: renders template, formats output, writes generated files, optional sorting. |
structs/resolve.go |
AST parsing helpers, JSON tag extraction, and type-flattening rules. |
structs/options.go |
Generator options (package name, header, scalar handling, sorting). |
structs/templates/struct.go.tpl |
Template for the generated flattened struct definition. |
structs/testdata/input.go |
Input models used by tests to validate flattening behavior. |
structs/flatten_test.go |
Snapshot tests validating output and edge cases/errors. |
structs/.snapshots/* |
Approved snapshots for generator output across scenarios. |
cmd/flatten/main.go |
CLI wrapper for running the generator via go run / go:generate. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
erezrokah
approved these changes
Mar 24, 2026
kodiakhq bot
pushed a commit
that referenced
this pull request
Mar 24, 2026
🤖 I have created a release *beep* *boop* --- ## [0.4.0](v0.3.37...v0.4.0) (2026-03-24) ### Features * Implement type flattener ([#419](#419)) ([de8ece6](de8ece6)) ### Bug Fixes * **deps:** Update dependency go to v1.26.0 ([#414](#414)) ([94c3c5f](94c3c5f)) * **deps:** Update golang.org/x/exp digest to 3dfff04 ([#412](#412)) ([28e9880](28e9880)) * **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.94.3 ([#410](#410)) ([144ce71](144ce71)) * **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.94.4 ([#415](#415)) ([35c026e](35c026e)) * **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.94.5 ([#416](#416)) ([4586c6d](4586c6d)) * **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.94.6 ([#417](#417)) ([16902da](16902da)) * **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.94.7 ([#418](#418)) ([71d532b](71d532b)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
structspackage andcmd/flattenCLI to codegen that generates optimized Go structs from deeply nested API models. Nested struct fields are replaced with map[string]any to eliminate the decode -> allocate -> re-encode cycle when the SDK serializes them as JSON columns.Usage:
//go:generate go run github.com/cloudquery/codegen/cmd/flatten -source=../api/models.go -from=Finding -to=flatFinding -output=finding_generated.go -package=services -sort
Options: -sort (ID first, then alphabetical), -extra (prepend fields like AssetType), -package (output package name).