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

Method extendSchema

ext/dynblock/expand_body.go:92–126  ·  view source on GitHub ↗
(schema *hcl.BodySchema)

Source from the content-addressed store, hash-verified

90}
91
92func (b *expandBody) extendSchema(schema *hcl.BodySchema) *hcl.BodySchema {
93 // We augment the requested schema to also include our special "dynamic"
94 // block type, since then we'll get instances of it interleaved with
95 // all of the literal child blocks we must also include.
96 extSchema := &hcl.BodySchema{
97 Attributes: schema.Attributes,
98 Blocks: make([]hcl.BlockHeaderSchema, len(schema.Blocks), len(schema.Blocks)+len(b.hiddenBlocks)+1),
99 }
100 copy(extSchema.Blocks, schema.Blocks)
101 extSchema.Blocks = append(extSchema.Blocks, dynamicBlockHeaderSchema)
102
103 // If we have any hiddenBlocks then we also need to register those here
104 // so that a call to "Content" on the underlying body won't fail.
105 // (We'll filter these out again once we process the result of either
106 // Content or PartialContent.)
107 for _, blockS := range b.hiddenBlocks {
108 extSchema.Blocks = append(extSchema.Blocks, blockS)
109 }
110
111 // If we have any hiddenAttrs then we also need to register these, for
112 // the same reason as we deal with hiddenBlocks above.
113 if len(b.hiddenAttrs) != 0 {
114 newAttrs := make([]hcl.AttributeSchema, len(schema.Attributes), len(schema.Attributes)+len(b.hiddenAttrs))
115 copy(newAttrs, extSchema.Attributes)
116 for name := range b.hiddenAttrs {
117 newAttrs = append(newAttrs, hcl.AttributeSchema{
118 Name: name,
119 Required: false,
120 })
121 }
122 extSchema.Attributes = newAttrs
123 }
124
125 return extSchema
126}
127
128func (b *expandBody) prepareAttributes(rawAttrs hcl.Attributes) hcl.Attributes {
129 if len(b.hiddenAttrs) == 0 && b.iteration == nil && len(b.valueMarks) == 0 {

Callers 2

ContentMethod · 0.95
PartialContentMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected