config/configschema: Block.ImpliedType delegates to zcldec
zcldec now has its own function for computing the implied type for a spec, so we can use that instead of our own logic. The zcldec logic is more general since its spec model is more general than our schema model here, but it produces the same results for the subset of specifications that our DecoderSpec method produces.
This commit is contained in:
parent
2b622fe31a
commit
0ef985cada
|
@ -20,10 +20,6 @@ func (b *Block) DecoderSpec() hcldec.Spec {
|
|||
return ret
|
||||
}
|
||||
|
||||
// If the behavior here is changed, usually the behavior of ImpliedType
|
||||
// must be changed to match. It is required that this method produce
|
||||
// a specification that decodes into a value of the implied type.
|
||||
|
||||
for name, attrS := range b.Attributes {
|
||||
switch {
|
||||
case attrS.Computed && attrS.Optional:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package configschema
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/hcl2/hcldec"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
|
@ -16,37 +17,5 @@ func (b *Block) ImpliedType() cty.Type {
|
|||
return cty.EmptyObject
|
||||
}
|
||||
|
||||
attrTypes := map[string]cty.Type{}
|
||||
|
||||
for name, attrS := range b.Attributes {
|
||||
attrTypes[name] = attrS.Type
|
||||
}
|
||||
|
||||
for name, blockS := range b.BlockTypes {
|
||||
if _, exists := attrTypes[name]; exists {
|
||||
// This indicates an invalid schema, since it's not valid to
|
||||
// define both an attribute and a block type of the same name.
|
||||
// However, we don't raise this here since it's checked by
|
||||
// InternalValidate.
|
||||
continue
|
||||
}
|
||||
|
||||
childType := blockS.Block.ImpliedType()
|
||||
switch blockS.Nesting {
|
||||
case NestingSingle:
|
||||
attrTypes[name] = childType
|
||||
case NestingList:
|
||||
attrTypes[name] = cty.List(childType)
|
||||
case NestingSet:
|
||||
attrTypes[name] = cty.Set(childType)
|
||||
case NestingMap:
|
||||
attrTypes[name] = cty.Map(childType)
|
||||
default:
|
||||
// Invalid nesting type is just ignored. It's checked by
|
||||
// InternalValidate.
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return cty.Object(attrTypes)
|
||||
return hcldec.ImpliedType(b.DecoderSpec())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue