From 096a4066913ffaa73e7c9303705365128faf1e0a Mon Sep 17 00:00:00 2001 From: Levi Blackstone Date: Mon, 22 Jun 2020 10:27:17 -0600 Subject: [PATCH] [codegen] Generate correct opts type for ComponentResources (#4853) The docs generator previously assumed that the opts parameter for every resource was of the CustomResource type. This is incorrect for the YAML and Helm overlays, which are ComponentResources. This should be handled more generally once our schema supports ComponentResources, but this fixes the docs for now. --- pkg/codegen/docs/gen.go | 19 +++++++++++++++---- pkg/codegen/docs/gen_kubernetes.go | 5 +++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/codegen/docs/gen.go b/pkg/codegen/docs/gen.go index 327ff0fcb..3ddb96fea 100644 --- a/pkg/codegen/docs/gen.go +++ b/pkg/codegen/docs/gen.go @@ -512,6 +512,7 @@ func (mod *modContext) genConstructorTS(r *schema.Resource, argsOptional bool) [ var argsType string var argsDocLink string + optsType := "CustomResourceOptions" // The args type for k8s package differs from the rest depending on whether we are dealing with // overlay resources or regular k8s resources. if isKubernetesPackage(mod.pkg) { @@ -528,6 +529,10 @@ func (mod *modContext) genConstructorTS(r *schema.Resource, argsOptional bool) [ // The args types themselves are all under the input types module path, so use the input type link for the args type. argsDocLink = docLangHelper.GetDocLinkForResourceInputOrOutputType(mod.pkg, modName, argsType, true) } + + if mod.isComponentResource() { + optsType = "ComponentResourceOptions" + } } else { argsType = name + "Args" // All args types are in the same module path as the resource class itself even though it is an "input" type. @@ -561,8 +566,8 @@ func (mod *modContext) genConstructorTS(r *schema.Resource, argsOptional bool) [ Name: "opts", OptionalFlag: "?", Type: propertyType{ - Name: "CustomResourceOptions", - Link: docLangHelper.GetDocLinkForPulumiType(mod.pkg, "CustomResourceOptions"), + Name: optsType, + Link: docLangHelper.GetDocLinkForPulumiType(mod.pkg, optsType), }, Comment: ctorOptsArgComment, }, @@ -631,6 +636,8 @@ func (mod *modContext) genConstructorCS(r *schema.Resource, argsOptional bool) [ } var argLangTypeName string + optsType := "CustomResourceOptions" + // Constructor argument types in the k8s package for C# use a different namespace path. // K8s overlay resources are in the same namespace path as the resource itself. if isKubernetesPackage(mod.pkg) { @@ -649,6 +656,10 @@ func (mod *modContext) genConstructorCS(r *schema.Resource, argsOptional bool) [ } else { argLangTypeName = "Pulumi.Kubernetes." + name + "Args" } + + if mod.isComponentResource() { + optsType = "ComponentResourceOptions" + } } else { argLangType := mod.typeString(argsSchemaType, "csharp", characteristics, false) argLangTypeName = strings.ReplaceAll(argLangType.Name, "Inputs.", "") @@ -687,8 +698,8 @@ func (mod *modContext) genConstructorCS(r *schema.Resource, argsOptional bool) [ OptionalFlag: "?", DefaultValue: " = null", Type: propertyType{ - Name: "CustomResourceOptions", - Link: docLangHelper.GetDocLinkForPulumiType(mod.pkg, "Pulumi.CustomResourceOptions"), + Name: optsType, + Link: docLangHelper.GetDocLinkForPulumiType(mod.pkg, fmt.Sprintf("Pulumi.%s", optsType)), }, Comment: ctorOptsArgComment, }, diff --git a/pkg/codegen/docs/gen_kubernetes.go b/pkg/codegen/docs/gen_kubernetes.go index 90414f79a..713fcf96d 100644 --- a/pkg/codegen/docs/gen_kubernetes.go +++ b/pkg/codegen/docs/gen_kubernetes.go @@ -39,6 +39,11 @@ func (mod *modContext) isKubernetesOverlayModule() bool { strings.HasPrefix(mod.mod, "helm") || strings.HasPrefix(mod.mod, "yaml") } +func (mod *modContext) isComponentResource() bool { + // TODO: Support this more generally. For now, only the Helm and YAML overlays use ComponentResources. + return strings.HasPrefix(mod.mod, "helm") || strings.HasPrefix(mod.mod, "yaml") +} + // getKubernetesOverlayPythonFormalParams returns the formal params to render // for a Kubernetes overlay resource. These resources do not follow convention // that other resources do, so it is best to manually set these.