]>
Commit | Line | Data |
---|---|---|
107c1cdb ND |
1 | package configschema |
2 | ||
3 | // NoneRequired returns a deep copy of the receiver with any required | |
4 | // attributes translated to optional. | |
5 | func (b *Block) NoneRequired() *Block { | |
6 | ret := &Block{} | |
7 | ||
8 | if b.Attributes != nil { | |
9 | ret.Attributes = make(map[string]*Attribute, len(b.Attributes)) | |
10 | } | |
11 | for name, attrS := range b.Attributes { | |
12 | ret.Attributes[name] = attrS.forceOptional() | |
13 | } | |
14 | ||
15 | if b.BlockTypes != nil { | |
16 | ret.BlockTypes = make(map[string]*NestedBlock, len(b.BlockTypes)) | |
17 | } | |
18 | for name, blockS := range b.BlockTypes { | |
19 | ret.BlockTypes[name] = blockS.noneRequired() | |
20 | } | |
21 | ||
22 | return ret | |
23 | } | |
24 | ||
25 | func (b *NestedBlock) noneRequired() *NestedBlock { | |
26 | ret := *b | |
27 | ret.Block = *(ret.Block.NoneRequired()) | |
28 | ret.MinItems = 0 | |
29 | ret.MaxItems = 0 | |
30 | return &ret | |
31 | } | |
32 | ||
33 | func (a *Attribute) forceOptional() *Attribute { | |
34 | ret := *a | |
35 | ret.Optional = true | |
36 | ret.Required = false | |
37 | return &ret | |
38 | } |