Skip to content

Commit

Permalink
[LTS v0.24] Format kind JSON the same way the manifest is formatted (#…
Browse files Browse the repository at this point in the history
…487)

The same change as #486,
but including the thema generation, targeting LTS v0.24 branch instead
of main.

Co-authored-by: Igor Suleymanov <[email protected]>
  • Loading branch information
IfSentient and radiohead authored Dec 2, 2024
1 parent bbd0371 commit 9448bf8
Show file tree
Hide file tree
Showing 6 changed files with 611 additions and 7 deletions.
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

0 comments on commit 9448bf8

Please sign in to comment.