Skip to content

Commit

Permalink
Merge #11576
Browse files Browse the repository at this point in the history
11576: Remove full package links from bound schema types r=iwahbe a=iwahbe

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes #9932

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Ian Wahbe <ian@wahbe.com>
  • Loading branch information
bors[bot] and iwahbe committed Dec 14, 2022
2 parents 46e2126 + 60483ed commit 2d5c95b
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 126 deletions.
143 changes: 92 additions & 51 deletions pkg/codegen/docs/gen.go

Large diffs are not rendered by default.

39 changes: 26 additions & 13 deletions pkg/codegen/docs/gen_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
go_gen "github.com/pulumi/pulumi/pkg/v3/codegen/go"
"github.com/pulumi/pulumi/pkg/v3/codegen/python"
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)

// functionDocArgs represents the args that a Function doc template needs.
Expand Down Expand Up @@ -98,8 +99,8 @@ func (mod *modContext) getFunctionResourceInfo(f *schema.Function, outputVersion
resultTypeName = fmt.Sprintf("%sOutput", resultTypeName)
}
case "csharp":
namespace := title(mod.pkg.Name, lang)
if ns, ok := dctx.csharpPkgInfo.Namespaces[mod.pkg.Name]; ok {
namespace := title(mod.pkg.Name(), lang)
if ns, ok := dctx.csharpPkgInfo.Namespaces[mod.pkg.Name()]; ok {
namespace = ns
}
resultTypeName = docLangHelper.GetResourceFunctionResultName(mod.mod, f)
Expand Down Expand Up @@ -152,12 +153,14 @@ func (mod *modContext) genFunctionTS(f *schema.Function, funcName string, output
},
})
}
def, err := mod.pkg.Definition()
contract.AssertNoError(err)
params = append(params, formalParam{
Name: "opts",
OptionalFlag: "?",
Type: propertyType{
Name: "InvokeOptions",
Link: docLangHelper.GetDocLinkForPulumiType(mod.pkg, "InvokeOptions"),
Link: docLangHelper.GetDocLinkForPulumiType(def, "InvokeOptions"),
},
})

Expand Down Expand Up @@ -227,13 +230,15 @@ func (mod *modContext) genFunctionCS(f *schema.Function, funcName string, output
})
}

def, err := mod.pkg.Definition()
contract.AssertNoError(err)
params = append(params, formalParam{
Name: "opts",
OptionalFlag: "?",
DefaultValue: " = null",
Type: propertyType{
Name: "InvokeOptions",
Link: docLangHelper.GetDocLinkForPulumiType(mod.pkg, "Pulumi.InvokeOptions"),
Link: docLangHelper.GetDocLinkForPulumiType(def, "Pulumi.InvokeOptions"),
},
})
return params
Expand Down Expand Up @@ -261,13 +266,15 @@ func (mod *modContext) genFunctionJava(f *schema.Function, funcName string, outp
},
})
}
def, err := mod.pkg.Definition()
contract.AssertNoError(err)

params = append(params, formalParam{
Name: "options",
OptionalFlag: "@Nullable",
Type: propertyType{
Name: "InvokeOptions",
Link: docLangHelper.GetDocLinkForPulumiType(mod.pkg, "InvokeOptions"),
Link: docLangHelper.GetDocLinkForPulumiType(def, "InvokeOptions"),
},
})
return params
Expand Down Expand Up @@ -297,7 +304,10 @@ func (mod *modContext) genFunctionPython(f *schema.Function, resourceName string
schemaType = codegen.PlainType(codegen.OptionalType(prop))
}

typ := docLanguageHelper.GetLanguageTypeString(mod.pkg, mod.mod,
def, err := mod.pkg.Definition()
contract.AssertNoError(err)

typ := docLanguageHelper.GetLanguageTypeString(def, mod.mod,
schemaType, true /*input*/)
params = append(params, formalParam{
Name: python.PyName(prop.Name),
Expand Down Expand Up @@ -391,13 +401,13 @@ func (mod *modContext) genFunctionHeader(f *schema.Function) header {
if mod.mod == "" {
baseDescription = fmt.Sprintf("Documentation for the %s.%s function "+
"with examples, input properties, output properties, "+
"and supporting types.", mod.pkg.Name, funcName)
titleTag = fmt.Sprintf("%s.%s", mod.pkg.Name, funcName)
"and supporting types.", mod.pkg.Name(), funcName)
titleTag = fmt.Sprintf("%s.%s", mod.pkg.Name(), funcName)
} else {
baseDescription = fmt.Sprintf("Documentation for the %s.%s.%s function "+
"with examples, input properties, output properties, "+
"and supporting types.", mod.pkg.Name, mod.mod, funcName)
titleTag = fmt.Sprintf("%s.%s.%s", mod.pkg.Name, mod.mod, funcName)
"and supporting types.", mod.pkg.Name(), mod.mod, funcName)
titleTag = fmt.Sprintf("%s.%s.%s", mod.pkg.Name(), mod.mod, funcName)
}

return header{
Expand Down Expand Up @@ -447,10 +457,13 @@ func (mod *modContext) genFunction(f *schema.Function) functionDocArgs {
funcNameMap[lang] = docHelper.GetFunctionName(mod.mod, f)
}

def, err := mod.pkg.Definition()
contract.AssertNoError(err)

packageDetails := packageDetails{
Repository: mod.pkg.Repository,
License: mod.pkg.License,
Notes: mod.pkg.Attribution,
Repository: def.Repository,
License: def.License,
Notes: def.Attribution,
}

docInfo := dctx.decomposeDocstring(f.Comment)
Expand Down
6 changes: 3 additions & 3 deletions pkg/codegen/docs/gen_kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
)

func isKubernetesPackage(pkg *schema.Package) bool {
return pkg.Name == "kubernetes"
func isKubernetesPackage(pkg schema.PackageReference) bool {
return pkg.Name() == "kubernetes"
}

func (mod *modContext) isKubernetesOverlayModule() bool {
Expand Down Expand Up @@ -142,7 +142,7 @@ func getKubernetesMod(pkg *schema.Package, token string, modules map[string]*mod
mod, ok := modules[modName]
if !ok {
mod = &modContext{
pkg: pkg,
pkg: pkg.Reference(),
mod: modName,
tool: tool,
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/codegen/docs/gen_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/pulumi/pulumi/pkg/v3/codegen/python"
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)

type methodDocArgs struct {
Expand Down Expand Up @@ -216,7 +217,9 @@ func (mod *modContext) genMethodPython(f *schema.Function) []formalParam {
}
})
for _, arg := range args {
typ := docLanguageHelper.GetLanguageTypeString(mod.pkg, mod.mod, arg.Type, true /*input*/)
def, err := mod.pkg.Definition()
contract.AssertNoError(err)
typ := docLanguageHelper.GetLanguageTypeString(def, mod.mod, arg.Type, true /*input*/)
var defaultValue string
if !arg.IsRequired() {
defaultValue = " = None"
Expand Down Expand Up @@ -322,7 +325,9 @@ func (mod *modContext) getMethodResult(r *schema.Resource, m *schema.Method) map
var resultTypeName string
for _, lang := range dctx.supportedLanguages {
if m.Function.Outputs != nil && len(m.Function.Outputs.Properties) > 0 {
resultTypeName = dctx.getLanguageDocHelper(lang).GetMethodResultName(mod.pkg, mod.mod, r, m)
def, err := mod.pkg.Definition()
contract.AssertNoError(err)
resultTypeName = dctx.getLanguageDocHelper(lang).GetMethodResultName(def, mod.mod, r, m)
}
resourceMap[lang] = propertyType{
Name: resultTypeName,
Expand Down
5 changes: 4 additions & 1 deletion pkg/codegen/go/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,10 @@ func (pkg *pkgContext) genResource(w io.Writer, r *schema.Resource, generateReso
}

func NeedsGoOutputVersion(f *schema.Function) bool {
fPkg := f.Package
fPkgRef := f.PackageReference

fPkg, err := fPkgRef.Definition()
contract.AssertNoError(err)

var goInfo GoPackageInfo

Expand Down
5 changes: 0 additions & 5 deletions pkg/codegen/schema/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,6 @@ func (t *types) bindObjectTypeDetails(path string, obj *ObjectType, token string
language[name] = json.RawMessage(raw)
}

obj.Package = t.pkg
obj.PackageReference = t.externalPackage()
obj.Token = token
obj.Comment = spec.Description
Expand All @@ -1135,7 +1134,6 @@ func (t *types) bindObjectTypeDetails(path string, obj *ObjectType, token string
obj.properties = propertyMap
obj.IsOverlay = spec.IsOverlay

obj.InputShape.Package = t.pkg
obj.InputShape.PackageReference = t.externalPackage()
obj.InputShape.Token = token
obj.InputShape.Comment = spec.Description
Expand Down Expand Up @@ -1193,7 +1191,6 @@ func (t *types) bindEnumType(token string, spec ComplexTypeSpec) (*EnumType, hcl
}

return &EnumType{
Package: t.pkg,
PackageReference: t.externalPackage(),
Token: token,
Elements: values,
Expand Down Expand Up @@ -1386,7 +1383,6 @@ func (t *types) bindResourceDetails(path, token string, spec ResourceSpec, decl
}

*decl = Resource{
Package: t.pkg,
PackageReference: t.externalPackage(),
Token: token,
Comment: spec.Description,
Expand Down Expand Up @@ -1506,7 +1502,6 @@ func (t *types) bindFunctionDef(token string) (*Function, hcl.Diagnostics, error
}

fn := &Function{
Package: t.pkg,
PackageReference: t.externalPackage(),
Token: token,
Comment: spec.Description,
Expand Down
24 changes: 6 additions & 18 deletions pkg/codegen/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ func (*ArrayType) isType() {}

// EnumType represents an enum.
type EnumType struct {
// Package is the type's package. Package will not be accurate for types loaded by
// reference. In that case, use PackageReference instead.
Package *Package
// PackageReference is the PackageReference that defines the resource.
PackageReference PackageReference
// Token is the type's Pulumi type token.
Expand Down Expand Up @@ -214,9 +211,6 @@ func (*UnionType) isType() {}

// ObjectType represents schematized maps from strings to particular types.
type ObjectType struct {
// Package is the package that defines the resource. Package will not be accurate for
// types loaded by reference. In that case, use PackageReference instead.
Package *Package
// PackageReference is the PackageReference that defines the resource.
PackageReference PackageReference
// Token is the type's Pulumi type token.
Expand Down Expand Up @@ -380,9 +374,6 @@ type Alias struct {

// Resource describes a Pulumi resource.
type Resource struct {
// Package is the package that defines the resource. Package will not be accurate for
// types loaded by reference. In that case, use PackageReference instead.
Package *Package
// PackageReference is the PackageReference that defines the resource.
PackageReference PackageReference
// Token is the resource's Pulumi type token.
Expand Down Expand Up @@ -530,9 +521,6 @@ type Method struct {

// Function describes a Pulumi function.
type Function struct {
// Package is the package that defines the function. Package will not be accurate for
// types loaded by reference. In that case, use PackageReference instead.
Package *Package
// PackageReference is the PackageReference that defines the function.
PackageReference PackageReference
// Token is the function's Pulumi type token.
Expand Down Expand Up @@ -1272,11 +1260,11 @@ func (pkg *Package) marshalType(t Type, plain bool) TypeSpec {
Plain: !plain,
}
case *ObjectType:
return TypeSpec{Ref: pkg.marshalTypeRef(t.Package, "types", t.Token)}
return TypeSpec{Ref: pkg.marshalTypeRef(t.PackageReference, "types", t.Token)}
case *EnumType:
return TypeSpec{Ref: pkg.marshalTypeRef(t.Package, "types", t.Token)}
return TypeSpec{Ref: pkg.marshalTypeRef(t.PackageReference, "types", t.Token)}
case *ResourceType:
return TypeSpec{Ref: pkg.marshalTypeRef(t.Resource.Package, "resources", t.Token)}
return TypeSpec{Ref: pkg.marshalTypeRef(t.Resource.PackageReference, "resources", t.Token)}
case *TokenType:
var defaultType string
if t.UnderlyingType != nil {
Expand Down Expand Up @@ -1311,15 +1299,15 @@ func (pkg *Package) marshalType(t Type, plain bool) TypeSpec {
}
}

func (pkg *Package) marshalTypeRef(container *Package, section, token string) string {
func (pkg *Package) marshalTypeRef(container PackageReference, section, token string) string {
token = url.PathEscape(token)

if container == pkg {
if p, err := container.Definition(); err == nil && p == pkg {
return fmt.Sprintf("#/%s/%s", section, token)
}

// TODO(schema): this isn't quite right--it doesn't handle schemas sourced from URLs--but it's good enough for now.
return fmt.Sprintf("/%s/%v/schema.json#/%s/%s", container.Name, container.Version, section, token)
return fmt.Sprintf("/%s/%v/schema.json#/%s/%s", container.Name(), container.Version(), section, token)
}

func marshalLanguage(lang map[string]interface{}) (map[string]RawMessage, error) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/codegen/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestImportSpec(t *testing.T) {
}

for _, r := range pkg.Resources {
assert.NotNil(t, r.Package, "expected resource %s to have an associated Package", r.Token)
assert.NotNil(t, r.PackageReference, "expected resource %s to have an associated Package", r.Token)
}
}

Expand Down Expand Up @@ -127,7 +127,6 @@ func TestEnums(t *testing.T) {
t.Error(err)
}
result := pkg.Types[0]
tt.expected.Package = pkg
tt.expected.PackageReference = pkg.Reference()
assert.Equal(t, tt.expected, result)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/hcl/v2 v2.14.0
github.com/hashicorp/hcl/v2 v2.14.1
github.com/iancoleman/strcase v0.2.0
github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd
github.com/mitchellh/copystructure v1.2.0
Expand All @@ -45,7 +45,7 @@ require (
github.com/stretchr/testify v1.8.0
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7
github.com/xeipuuv/gojsonschema v1.2.0
github.com/zclconf/go-cty v1.10.0
github.com/zclconf/go-cty v1.12.1
gocloud.dev v0.27.0
gocloud.dev/secrets/hashivault v0.27.0
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503
Expand All @@ -54,7 +54,7 @@ require (
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
google.golang.org/api v0.91.0
google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78
google.golang.org/grpc v1.49.0
google.golang.org/grpc v1.51.0
gopkg.in/yaml.v3 v3.0.1
pgregory.net/rapid v0.4.7
sourcegraph.com/sourcegraph/appdash v0.0.0-20211028080628-e2786a622600
Expand All @@ -71,7 +71,7 @@ require (
github.com/hexops/gotextdiff v1.0.3
github.com/muesli/cancelreader v0.2.2
github.com/natefinch/atomic v1.0.1
github.com/pulumi/pulumi-java/pkg v0.6.0
github.com/pulumi/pulumi-java/pkg v0.7.0
github.com/pulumi/pulumi-terraform-bridge/v3 v3.33.1-0.20221206123933-cdc390c674b1
github.com/pulumi/pulumi-yaml v1.0.4
github.com/rivo/uniseg v0.2.0
Expand Down Expand Up @@ -235,7 +235,7 @@ require (
go.opencensus.io v0.23.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 // indirect
golang.org/x/text v0.3.8 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down

0 comments on commit 2d5c95b

Please sign in to comment.