hcldec: ImpliedSchema must visit deep specs
Previously, due to a bug, it was only visiting the first two levels of specifications, missing anything referenced at lower levels.
This commit is contained in:
parent
a4ee7188ad
commit
cc215b6afe
@ -86,6 +86,23 @@ func TestDecode(t *testing.T) {
|
|||||||
cty.NumberIntVal(10),
|
cty.NumberIntVal(10),
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"a = 1\n",
|
||||||
|
ObjectSpec{
|
||||||
|
"foo": &DefaultSpec{
|
||||||
|
Primary: &AttrSpec{
|
||||||
|
Name: "a",
|
||||||
|
Type: cty.Number,
|
||||||
|
},
|
||||||
|
Default: &LiteralSpec{
|
||||||
|
Value: cty.NumberIntVal(10),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
nil,
|
||||||
|
cty.ObjectVal(map[string]cty.Value{"foo": cty.NumberIntVal(1)}),
|
||||||
|
0,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"a = \"1\"\n",
|
"a = \"1\"\n",
|
||||||
&AttrSpec{
|
&AttrSpec{
|
||||||
|
@ -14,7 +14,8 @@ func ImpliedSchema(spec Spec) *hcl.BodySchema {
|
|||||||
// visitSameBodyChildren walks through the spec structure, calling
|
// visitSameBodyChildren walks through the spec structure, calling
|
||||||
// the given callback for each descendent spec encountered. We are
|
// the given callback for each descendent spec encountered. We are
|
||||||
// interested in the specs that reference attributes and blocks.
|
// interested in the specs that reference attributes and blocks.
|
||||||
visit := func(s Spec) {
|
var visit visitFunc
|
||||||
|
visit = func(s Spec) {
|
||||||
if as, ok := s.(attrSpec); ok {
|
if as, ok := s.(attrSpec); ok {
|
||||||
attrs = append(attrs, as.attrSchemata()...)
|
attrs = append(attrs, as.attrSchemata()...)
|
||||||
}
|
}
|
||||||
@ -22,10 +23,11 @@ func ImpliedSchema(spec Spec) *hcl.BodySchema {
|
|||||||
if bs, ok := s.(blockSpec); ok {
|
if bs, ok := s.(blockSpec); ok {
|
||||||
blocks = append(blocks, bs.blockHeaderSchemata()...)
|
blocks = append(blocks, bs.blockHeaderSchemata()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.visitSameBodyChildren(visit)
|
||||||
}
|
}
|
||||||
|
|
||||||
visit(spec)
|
visit(spec)
|
||||||
spec.visitSameBodyChildren(visit)
|
|
||||||
|
|
||||||
return &hcl.BodySchema{
|
return &hcl.BodySchema{
|
||||||
Attributes: attrs,
|
Attributes: attrs,
|
||||||
|
Loading…
Reference in New Issue
Block a user