Skip to content

Commit

Permalink
Simplify call to tfbridge.IsMaxItemsOne
Browse files Browse the repository at this point in the history
The body is `tfbridge.IsMaxItemsOne` is:

```go
func IsMaxItemsOne(tfs shim.Schema, info *SchemaInfo) bool {
	if tfs == nil {
		return false
	}
	if tfs.Type() != shim.TypeList && tfs.Type() != shim.TypeSet {
		return false
	}
	if info != nil && info.MaxItemsOne != nil {
		return *info.MaxItemsOne
	}
	return tfs.MaxItems() == 1
}
```

Thus, checking if `tfs` is of `shim.Type{List,Set}` before calling
`tfbridge.IsMaxItemsOne` is redundant.
  • Loading branch information
iwahbe committed Aug 14, 2024
1 parent 95ee4a1 commit 992ffd4
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions pkg/tfgen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,8 @@ func (g *Generator) makePropertyType(typePath paths.TypePath,
return g.makeObjectPropertyType(typePath, blockType, elemInfo, out, entityDocs)
}

// IsMaxItemOne lists and sets are flattened, transforming List[T] to T. Detect if this is the case.
flatten := false
switch sch.Type() {
case shim.TypeList, shim.TypeSet:
if tfbridge.IsMaxItemsOne(sch, info) {
flatten = true
}
}
// IsMaxItemOne lists and sets are flattened, transforming List[T] or Set[T] to T. Detect if this is the case.
flatten := tfbridge.IsMaxItemsOne(sch, info)

// The remaining cases are collections, List[T], Set[T] or Map[T], and recursion needs NewElementPath except for
// flattening that stays at the current path.
Expand Down

0 comments on commit 992ffd4

Please sign in to comment.