Handle arrays/maps of external refs as pointers
This commit is contained in:
parent
d3187d630f
commit
7cba9df480
1 changed files with 28 additions and 6 deletions
|
@ -226,9 +226,19 @@ func (pkg *pkgContext) plainType(t schema.Type, optional bool) string {
|
||||||
case *schema.EnumType:
|
case *schema.EnumType:
|
||||||
return pkg.plainType(t.ElementType, optional)
|
return pkg.plainType(t.ElementType, optional)
|
||||||
case *schema.ArrayType:
|
case *schema.ArrayType:
|
||||||
return "[]" + pkg.plainType(t.ElementType, false)
|
typ = "[]"
|
||||||
|
if pkg.isExternalReference(t.ElementType) {
|
||||||
|
typ += "*"
|
||||||
|
}
|
||||||
|
typ += pkg.plainType(t.ElementType, false)
|
||||||
|
return typ
|
||||||
case *schema.MapType:
|
case *schema.MapType:
|
||||||
return "map[string]" + pkg.plainType(t.ElementType, false)
|
typ = "map[string]"
|
||||||
|
if pkg.isExternalReference(t.ElementType) {
|
||||||
|
typ += "*"
|
||||||
|
}
|
||||||
|
typ += pkg.plainType(t.ElementType, false)
|
||||||
|
return typ
|
||||||
case *schema.ObjectType:
|
case *schema.ObjectType:
|
||||||
typ = pkg.resolveObjectType(t)
|
typ = pkg.resolveObjectType(t)
|
||||||
case *schema.ResourceType:
|
case *schema.ResourceType:
|
||||||
|
@ -295,7 +305,8 @@ func (pkg *pkgContext) inputType(t schema.Type, optional bool) string {
|
||||||
case *schema.ObjectType:
|
case *schema.ObjectType:
|
||||||
typ = pkg.resolveObjectType(t)
|
typ = pkg.resolveObjectType(t)
|
||||||
case *schema.ResourceType:
|
case *schema.ResourceType:
|
||||||
return pkg.resolveResourceType(t) + "Input"
|
typ = pkg.resolveResourceType(t)
|
||||||
|
return typ + "Input"
|
||||||
case *schema.TokenType:
|
case *schema.TokenType:
|
||||||
// Use the underlying type for now.
|
// Use the underlying type for now.
|
||||||
if t.UnderlyingType != nil {
|
if t.UnderlyingType != nil {
|
||||||
|
@ -339,12 +350,22 @@ func (pkg *pkgContext) inputType(t schema.Type, optional bool) string {
|
||||||
return typ + "Input"
|
return typ + "Input"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pkg *pkgContext) isExternalReference(t schema.Type) bool {
|
||||||
|
switch typ := t.(type) {
|
||||||
|
case *schema.ObjectType:
|
||||||
|
return typ.Package != nil && pkg.pkg != nil && typ.Package != pkg.pkg
|
||||||
|
case *schema.ResourceType:
|
||||||
|
return typ.Resource != nil && pkg.pkg != nil && typ.Resource.Package != pkg.pkg
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// resolveResourceType resolves resource references in properties while
|
// resolveResourceType resolves resource references in properties while
|
||||||
// taking into account potential external resources. Returned type is
|
// taking into account potential external resources. Returned type is
|
||||||
// always marked as required. Caller should check if the property is
|
// always marked as required. Caller should check if the property is
|
||||||
// optional and convert the type to a pointer if necessary.
|
// optional and convert the type to a pointer if necessary.
|
||||||
func (pkg *pkgContext) resolveResourceType(t *schema.ResourceType) string {
|
func (pkg *pkgContext) resolveResourceType(t *schema.ResourceType) string {
|
||||||
if t.Resource == nil || pkg.pkg == nil || t.Resource.Package == pkg.pkg {
|
if !pkg.isExternalReference(t) {
|
||||||
return pkg.tokenToResource(t.Token)
|
return pkg.tokenToResource(t.Token)
|
||||||
}
|
}
|
||||||
extPkg := t.Resource.Package
|
extPkg := t.Resource.Package
|
||||||
|
@ -372,7 +393,7 @@ func (pkg *pkgContext) resolveResourceType(t *schema.ResourceType) string {
|
||||||
// always marked as required. Caller should check if the property is
|
// always marked as required. Caller should check if the property is
|
||||||
// optional and convert the type to a pointer if necessary.
|
// optional and convert the type to a pointer if necessary.
|
||||||
func (pkg *pkgContext) resolveObjectType(t *schema.ObjectType) string {
|
func (pkg *pkgContext) resolveObjectType(t *schema.ObjectType) string {
|
||||||
if t.Package == nil || pkg.pkg == nil || t.Package == pkg.pkg {
|
if !pkg.isExternalReference(t) {
|
||||||
return pkg.tokenToType(t.Token)
|
return pkg.tokenToType(t.Token)
|
||||||
}
|
}
|
||||||
extPkg := t.Package
|
extPkg := t.Package
|
||||||
|
@ -411,7 +432,8 @@ func (pkg *pkgContext) outputType(t schema.Type, optional bool) string {
|
||||||
case *schema.ObjectType:
|
case *schema.ObjectType:
|
||||||
typ = pkg.resolveObjectType(t)
|
typ = pkg.resolveObjectType(t)
|
||||||
case *schema.ResourceType:
|
case *schema.ResourceType:
|
||||||
return pkg.resolveResourceType(t) + "Output"
|
typ = pkg.resolveResourceType(t)
|
||||||
|
return typ + "Output"
|
||||||
case *schema.TokenType:
|
case *schema.TokenType:
|
||||||
// Use the underlying type for now.
|
// Use the underlying type for now.
|
||||||
if t.UnderlyingType != nil {
|
if t.UnderlyingType != nil {
|
||||||
|
|
Loading…
Reference in a new issue