MCPcopy
hub / github.com/hashicorp/hcl / ImpliedSchema

Function ImpliedSchema

hcldec/schema.go:13–39  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

11// This is the schema that the Decode function will use internally to
12// access the content of a given body.
13func 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}

Callers 4

walkVariablesWithHCLDecFunction · 0.92
VariablesFunction · 0.85
decodeFunction · 0.85
sourceRangeFunction · 0.85

Calls 3

attrSchemataMethod · 0.65
blockHeaderSchemataMethod · 0.65
visitSameBodyChildrenMethod · 0.65

Tested by

no test coverage detected