ImpliedSchema returns the *hcl.BodySchema implied by the given specification. This is the schema that the Decode function will use internally to access the content of a given body.
(spec Spec)
| 11 | // This is the schema that the Decode function will use internally to |
| 12 | // access the content of a given body. |
| 13 | func ImpliedSchema(spec Spec) *hcl.BodySchema { |
| 14 | var attrs []hcl.AttributeSchema |
| 15 | var blocks []hcl.BlockHeaderSchema |
| 16 | |
| 17 | // visitSameBodyChildren walks through the spec structure, calling |
| 18 | // the given callback for each descendent spec encountered. We are |
| 19 | // interested in the specs that reference attributes and blocks. |
| 20 | var visit visitFunc |
| 21 | visit = func(s Spec) { |
| 22 | if as, ok := s.(attrSpec); ok { |
| 23 | attrs = append(attrs, as.attrSchemata()...) |
| 24 | } |
| 25 | |
| 26 | if bs, ok := s.(blockSpec); ok { |
| 27 | blocks = append(blocks, bs.blockHeaderSchemata()...) |
| 28 | } |
| 29 | |
| 30 | s.visitSameBodyChildren(visit) |
| 31 | } |
| 32 | |
| 33 | visit(spec) |
| 34 | |
| 35 | return &hcl.BodySchema{ |
| 36 | Attributes: attrs, |
| 37 | Blocks: blocks, |
| 38 | } |
| 39 | } |
no test coverage detected