@@ -16,7 +16,6 @@ import (
1616
1717var RegexpModelName = regexp .MustCompile ("^[a-z_][a-z_0-9]{0,57}$" )
1818var RegexpPropName = regexp .MustCompile ("^[a-z_][a-z_0-9]{0,62}$" )
19- var RegexpPropRelaxedName = regexp .MustCompile ("^[a-z_][a-z_0-9\\ -]{0,62}$" )
2019var RegexpMapKey = regexp .MustCompile ("^[a-z0-9][a-z0-9_.:\\ -]{0,62}$" )
2120var RegexpID = regexp .MustCompile ("^[a-zA-Z0-9_][a-zA-Z0-9_.\\ -~@]{0,127}$" )
2221
@@ -40,14 +39,6 @@ func IsValidAttributeName(name string) error {
4039 name , RegexpPropName .String ())
4140}
4241
43- func IsValidAttributeRelaxedName (name string ) error {
44- if RegexpPropRelaxedName .MatchString (name ) {
45- return nil
46- }
47- return fmt .Errorf ("Invalid attribute name %q, must match: %s" ,
48- name , RegexpPropRelaxedName .String ())
49- }
50-
5142func IsValidMapKey (key string ) error {
5243 if RegexpMapKey .MatchString (key ) {
5344 return nil
@@ -93,18 +84,18 @@ type AttrInternals struct {
9384// 'false', but Strict needs to default to 'true'. See the custome Unmarshal
9485// funcs in model.go for how we set those
9586type Attribute struct {
96- Model * Model `json:"-"`
97- Name string `json:"name,omitempty"`
98- Type string `json:"type,omitempty"`
99- Target string `json:"target,omitempty"`
100- RelaxedNames bool `json:"relaxednames ,omitempty"`
101- Description string `json:"description,omitempty"`
102- Enum []any `json:"enum,omitempty"` // just scalars though
103- Strict * bool `json:"strict,omitempty"`
104- ReadOnly bool `json:"readonly,omitempty"`
105- Immutable bool `json:"immutable,omitempty"`
106- Required bool `json:"required,omitempty"`
107- Default any `json:"default,omitempty"`
87+ Model * Model `json:"-"`
88+ Name string `json:"name,omitempty"`
89+ Type string `json:"type,omitempty"`
90+ Target string `json:"target,omitempty"`
91+ NameCharSet string `json:"namecharset ,omitempty"`
92+ Description string `json:"description,omitempty"`
93+ Enum []any `json:"enum,omitempty"` // just scalars though
94+ Strict * bool `json:"strict,omitempty"`
95+ ReadOnly bool `json:"readonly,omitempty"`
96+ Immutable bool `json:"immutable,omitempty"`
97+ Required bool `json:"required,omitempty"`
98+ Default any `json:"default,omitempty"`
10899
109100 Attributes Attributes `json:"attributes,omitempty"` // for Objs
110101 Item * Item `json:"item,omitempty"` // for maps & arrays
@@ -118,17 +109,17 @@ type Attribute struct {
118109}
119110
120111type Item struct { // for maps and arrays
121- Model * Model `json:"-"`
122- Type string `json:"type,omitempty"`
123- RelaxedNames bool `json:"relaxednames ,omitempty"` // when 'type'=obj
124- Attributes Attributes `json:"attributes,omitempty"` // when 'type'=obj
125- Item * Item `json:"item,omitempty"` // when 'type'=map,array
112+ Model * Model `json:"-"`
113+ Type string `json:"type,omitempty"`
114+ NameCharSet string `json:"namecharset ,omitempty"` // when 'type'=obj
115+ Attributes Attributes `json:"attributes,omitempty"` // when 'type'=obj
116+ Item * Item `json:"item,omitempty"` // when 'type'=map,array
126117}
127118
128119type IfValues map [string ]* IfValue
129120
130121type IfValue struct {
131- SiblingAttributes Attributes `json:"siblingAttributes ,omitempty"`
122+ SiblingAttributes Attributes `json:"siblingattributes ,omitempty"`
132123}
133124
134125type GroupModel struct {
@@ -627,13 +618,25 @@ func (i *Item) AddAttribute(attr *Attribute) (*Attribute, error) {
627618 }
628619
629620 if attr .Name != "*" {
630- if i .RelaxedNames {
631- if err := IsValidAttributeRelaxedName (attr .Name ); err != nil {
632- return nil , err
621+ if i .Type == OBJECT {
622+ if i .NameCharSet == "extended" {
623+ if err := IsValidMapKey (attr .Name ); err != nil {
624+ return nil , fmt .Errorf ("Invalid attribute name %q, must " +
625+ "match: %s" , attr .Name , RegexpMapKey .String ())
626+ }
627+ } else if i .NameCharSet == "strict" || i .NameCharSet == "" {
628+ if err := IsValidAttributeName (attr .Name ); err != nil {
629+ return nil , err
630+ }
631+ } else {
632+ return nil , fmt .Errorf ("Invalid \" namecharset\" value: %s" ,
633+ i .NameCharSet )
633634 }
634635 } else {
635- if err := IsValidAttributeName (attr .Name ); err != nil {
636- return nil , err
636+ if attr .NameCharSet != "" {
637+ return nil , fmt .Errorf ("Attribute %q must not have a " +
638+ "\" namecharset\" value unless its type is \" object\" " ,
639+ attr .Name )
637640 }
638641 }
639642 }
@@ -1480,13 +1483,25 @@ func (a *Attribute) AddAttrArray(name string, item *Item) (*Attribute, error) {
14801483}
14811484func (a * Attribute ) AddAttribute (attr * Attribute ) (* Attribute , error ) {
14821485 if attr .Name != "*" {
1483- if a .RelaxedNames {
1484- if err := IsValidAttributeRelaxedName (attr .Name ); err != nil {
1485- return nil , err
1486+ if a .Type == OBJECT {
1487+ if a .NameCharSet == "extended" {
1488+ if err := IsValidMapKey (attr .Name ); err != nil {
1489+ return nil , fmt .Errorf ("Invalid attribute name %q, must " +
1490+ "match: %s" , attr .Name , RegexpMapKey .String ())
1491+ }
1492+ } else if a .NameCharSet == "strict" || a .NameCharSet == "" {
1493+ if err := IsValidAttributeName (attr .Name ); err != nil {
1494+ return nil , err
1495+ }
1496+ } else {
1497+ return nil , fmt .Errorf ("Invalid \" namecharset\" value: %s" ,
1498+ a .NameCharSet )
14861499 }
14871500 } else {
1488- if err := IsValidAttributeName (attr .Name ); err != nil {
1489- return nil , err
1501+ if a .NameCharSet != "" {
1502+ return nil , fmt .Errorf ("Attribute %q must not have a " +
1503+ "\" namecharset\" value unless it is of type \" object\" " ,
1504+ a .Name )
14901505 }
14911506 }
14921507 }
@@ -1582,7 +1597,7 @@ func (m *Model) Verify() error {
15821597 AttrNames : map [string ]bool {},
15831598 Path : NewPPP ("model" ),
15841599 }
1585- if err := m .Attributes .Verify (false , ld ); err != nil {
1600+ if err := m .Attributes .Verify ("strict" , ld ); err != nil {
15861601 return err
15871602 }
15881603
@@ -1678,7 +1693,7 @@ func (gm *GroupModel) Verify(gmName string) error {
16781693 AttrNames : map [string ]bool {},
16791694 Path : NewPPP ("groups" ).P (gm .Plural ),
16801695 }
1681- if err := gm .Attributes .Verify (false , ld ); err != nil {
1696+ if err := gm .Attributes .Verify ("strict" , ld ); err != nil {
16821697 return err
16831698 }
16841699
@@ -1820,7 +1835,7 @@ func (rm *ResourceModel) Verify(rmName string) error {
18201835 // attrs[rm.Singular+"base64"] = &Attribute{Name: rm.Singular + "base64", Type: STRING}
18211836 }
18221837
1823- if err := attrs .Verify (false , ld ); err != nil {
1838+ if err := attrs .Verify ("strict" , ld ); err != nil {
18241839 return err
18251840 }
18261841
@@ -2189,7 +2204,7 @@ func ConvertString(val string, toType string) (any, bool) {
21892204var targetREstr = `^(?:/([^/]+)(?:/([^[/]+)(?:(?:/(versions)|(\[(?:/versions)]))?))?)?$`
21902205var targetRE = regexp .MustCompile (targetREstr )
21912206
2192- func (attrs Attributes ) Verify (relaxedNames bool , ld * LevelData ) error {
2207+ func (attrs Attributes ) Verify (namecharset string , ld * LevelData ) error {
21932208 ld = & LevelData {
21942209 Model : ld .Model ,
21952210 AttrNames : maps .Clone (ld .AttrNames ),
@@ -2219,14 +2234,17 @@ func (attrs Attributes) Verify(relaxedNames bool, ld *LevelData) error {
22192234 // Technically we should convert the XXXid into id but any XXXid needs
22202235 // to be a valid name/string so we should be ok
22212236 if name != "*" && SpecProps [name ] == nil {
2222- if relaxedNames {
2223- if err := IsValidAttributeRelaxedName (name ); err != nil {
2237+ if namecharset == "extended" {
2238+ if err := IsValidMapKey (name ); err != nil {
22242239 return fmt .Errorf ("Error processing %q: %s" , ld .Path .UI (), err )
22252240 }
2226- } else {
2241+ } else if namecharset == "strict" || namecharset == "" {
22272242 if err := IsValidAttributeName (name ); err != nil {
22282243 return fmt .Errorf ("Error processing %q: %s" , ld .Path .UI (), err )
22292244 }
2245+ } else {
2246+ return fmt .Errorf ("Invalid \" namecharset\" value: %s" ,
2247+ namecharset )
22302248 }
22312249 }
22322250 path := ld .Path .P (name )
@@ -2322,12 +2340,23 @@ func (attrs Attributes) Verify(relaxedNames bool, ld *LevelData) error {
23222340 }
23232341
23242342 if attr .Type == OBJECT {
2343+ if attr .NameCharSet != "" && attr .NameCharSet != "strict" && attr .NameCharSet != "extended" {
2344+ return fmt .Errorf ("%q has an invalid \" namecharset\" value: " +
2345+ attr .NameCharSet , path .UI ())
2346+ }
2347+
23252348 if attr .Item != nil {
23262349 return fmt .Errorf ("%q must not have an \" item\" section" , path .UI ())
23272350 }
2328- if err := attr .Attributes .Verify (attr .RelaxedNames , & LevelData {ld .Model , nil , path }); err != nil {
2351+ if err := attr .Attributes .Verify (attr .NameCharSet , & LevelData {ld .Model , nil , path }); err != nil {
23292352 return err
23302353 }
2354+ } else {
2355+ if attr .NameCharSet != "" {
2356+ return fmt .Errorf ("Attribute %q must not have a " +
2357+ "\" namecharset\" value unless its type is \" object\" " ,
2358+ attr .Name )
2359+ }
23312360 }
23322361
23332362 if attr .Item != nil {
@@ -2359,7 +2388,7 @@ func (attrs Attributes) Verify(relaxedNames bool, ld *LevelData) error {
23592388 ld .Path .P (attr .Name ).P ("ifvalues" ).P (valStr )}
23602389
23612390 // Recursive
2362- if err := ifValue .SiblingAttributes .Verify (relaxedNames , nextLD ); err != nil {
2391+ if err := ifValue .SiblingAttributes .Verify (namecharset , nextLD ); err != nil {
23632392 return err
23642393 }
23652394 }
@@ -2414,8 +2443,20 @@ func (item *Item) Verify(path *PropPath) error {
24142443 }
24152444 }
24162445
2446+ if item .Type == OBJECT {
2447+ if item .NameCharSet != "" && item .NameCharSet != "strict" && item .NameCharSet != "extended" {
2448+ return fmt .Errorf ("Invalid \" namecharset\" value: %s" ,
2449+ item .NameCharSet )
2450+ }
2451+ } else {
2452+ if item .NameCharSet != "" {
2453+ return fmt .Errorf ("%q must not have a \" namecharset\" value " +
2454+ "since it is not of type \" object\" " , p .UI ())
2455+ }
2456+ }
2457+
24172458 if item .Attributes != nil {
2418- if err := item .Attributes .Verify (item .RelaxedNames , & LevelData {item .Model , nil , p }); err != nil {
2459+ if err := item .Attributes .Verify (item .NameCharSet , & LevelData {item .Model , nil , p }); err != nil {
24192460 return err
24202461 }
24212462 }
0 commit comments