Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LTS v0.24] Format kind JSON the same way the manifest is formatted #487

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cmd/grafana-app-sdk/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ func generateCRDsThema(parser *themagen.CustomKindParser, genPath string, encodi
ms = themagen.CRDGenerator(yaml.Marshal, "yaml")
} else {
// Assume JSON
ms = themagen.CRDGenerator(json.Marshal, "json")
ms = themagen.CRDGenerator(func(v any) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
}, "json")
}
files, err := parser.FilteredGenerate(themagen.Filter(ms, func(c kindsys.Custom) bool {
return c.Def().Properties.IsCRD
Expand Down Expand Up @@ -383,7 +385,9 @@ func generateKindsCue(modFS fs.FS, cfg kindGenConfig, selectors ...string) (code
// CRD
var crdFiles codejen.Files
if cfg.CRDEncoding != "none" {
encFunc := json.Marshal
encFunc := func(v any) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
}
if cfg.CRDEncoding == "yaml" {
encFunc = yaml.Marshal
}
Expand Down
4 changes: 3 additions & 1 deletion codegen/cuekind/generators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ func TestCRDGenerator(t *testing.T) {
require.Nil(t, err)

t.Run("JSON", func(t *testing.T) {
files, err := CRDGenerator(json.Marshal, "json").Generate(kinds...)
files, err := CRDGenerator(func(v any) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
}, "json").Generate(kinds...)
require.Nil(t, err)
// Check number of files generated
assert.Len(t, files, 2)
Expand Down
Loading
Loading