diff --git a/CHANGELOG.md b/CHANGELOG.md index d36a5fd..e9981a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # CHANGELOG -## Unreleased +## 1.5.4 (2024-11-13) + +- NodeJS now uses correct input/output types for object metadata. (https://github.com/pulumi/crd2pulumi/issues/158) ## 1.5.3 (2024-09-30) diff --git a/pkg/codegen/nodejs.go b/pkg/codegen/nodejs.go index cce2c26..c82306b 100644 --- a/pkg/codegen/nodejs.go +++ b/pkg/codegen/nodejs.go @@ -30,7 +30,7 @@ export type ObjectMetaPatch = k8s.types.input.meta.v1.ObjectMetaPatch; ` func GenerateNodeJS(pg *PackageGenerator, name string) (map[string]*bytes.Buffer, error) { - pkg := pg.SchemaPackage() + pkg := pg.SchemaPackageWithObjectMetaType() oldName := pkg.Name pkg.Name = name diff --git a/tests/crds_test.go b/tests/crds_test.go index f94129a..f2171e9 100644 --- a/tests/crds_test.go +++ b/tests/crds_test.go @@ -259,6 +259,29 @@ func TestKubernetesVersionNodeJs(t *testing.T) { execCrd2Pulumi(t, "nodejs", "crds/k8sversion/mock_crd.yaml", validateVersion) } +func TestNodeJsObjectMeta(t *testing.T) { + validateVersion := func(t *testing.T, path string) { + // enter and build the generated package + withDir(t, path, func() { + runRequireNoError(t, exec.Command("npm", "install")) + runRequireNoError(t, exec.Command("npm", "run", "build")) + + filename := filepath.Join(path, "k8sversion", "test", "testResource.ts") + t.Logf("validating objectmeta type in %s", filename) + + testResource, err := os.ReadFile(filename) + if err != nil { + t.Fatalf("expected to read generated NodeJS code: %s", err) + } + + assert.Contains(t, string(testResource), "public readonly metadata!: pulumi.Output;", "expected metadata output type") + assert.Contains(t, string(testResource), "metadata?: pulumi.Input;", "expected metadata input type") + }) + } + + execCrd2Pulumi(t, "nodejs", "crds/k8sversion/mock_crd.yaml", validateVersion) +} + func withDir(t *testing.T, dir string, f func()) { pwd, err := os.Getwd() require.NoError(t, err)