@@ -11,7 +11,7 @@ import (
1111 "github.com/hashicorp/terraform-plugin-codegen-spec/schema"
1212)
1313
14- func (s * OASSchema ) BuildResourceAttributes () (attrmapper.ResourceAttributes , * PropertyError ) {
14+ func (s * OASSchema ) BuildResourceAttributes () (attrmapper.ResourceAttributes , * SchemaError ) {
1515 objectAttributes := attrmapper.ResourceAttributes {}
1616
1717 // TODO: throw error if it's not an object?
@@ -23,12 +23,12 @@ func (s *OASSchema) BuildResourceAttributes() (attrmapper.ResourceAttributes, *P
2323 pProxy := s .Schema .Properties [name ]
2424 pSchema , err := BuildSchema (pProxy , SchemaOpts {}, s .GlobalSchemaOpts )
2525 if err != nil {
26- return nil , s .NewPropertyError (err , name )
26+ return nil , s .NestSchemaError (err , name )
2727 }
2828
29- attribute , propErr := pSchema .BuildResourceAttribute (name , s .GetComputability (name ))
30- if propErr != nil {
31- return nil , propErr
29+ attribute , err := pSchema .BuildResourceAttribute (name , s .GetComputability (name ))
30+ if err != nil {
31+ return nil , err
3232 }
3333
3434 objectAttributes = append (objectAttributes , attribute )
@@ -37,7 +37,11 @@ func (s *OASSchema) BuildResourceAttributes() (attrmapper.ResourceAttributes, *P
3737 return objectAttributes , nil
3838}
3939
40- func (s * OASSchema ) BuildResourceAttribute (name string , computability schema.ComputedOptionalRequired ) (attrmapper.ResourceAttribute , * PropertyError ) {
40+ func (s * OASSchema ) BuildResourceAttribute (name string , computability schema.ComputedOptionalRequired ) (attrmapper.ResourceAttribute , * SchemaError ) {
41+ if util .TerraformIdentifier (name ) == "" {
42+ return nil , s .SchemaErrorFromProperty (fmt .Errorf ("'%s' cannot be converted to a valid Terraform identifier" , name ), name )
43+ }
44+
4145 switch s .Type {
4246 case util .OAS_type_string :
4347 return s .BuildStringResource (name , computability )
@@ -55,11 +59,11 @@ func (s *OASSchema) BuildResourceAttribute(name string, computability schema.Com
5559 }
5660 return s .BuildSingleNestedResource (name , computability )
5761 default :
58- return nil , s .NewPropertyError (fmt .Errorf ("invalid schema type '%s'" , s .Type ), name )
62+ return nil , s .SchemaErrorFromProperty (fmt .Errorf ("invalid schema type '%s'" , s .Type ), name )
5963 }
6064}
6165
62- func (s * OASSchema ) BuildDataSourceAttributes () (attrmapper.DataSourceAttributes , * PropertyError ) {
66+ func (s * OASSchema ) BuildDataSourceAttributes () (attrmapper.DataSourceAttributes , * SchemaError ) {
6367 objectAttributes := attrmapper.DataSourceAttributes {}
6468
6569 // TODO: throw error if it's not an object?
@@ -71,12 +75,12 @@ func (s *OASSchema) BuildDataSourceAttributes() (attrmapper.DataSourceAttributes
7175 pProxy := s .Schema .Properties [name ]
7276 pSchema , err := BuildSchema (pProxy , SchemaOpts {}, s .GlobalSchemaOpts )
7377 if err != nil {
74- return nil , s .NewPropertyError (err , name )
78+ return nil , s .NestSchemaError (err , name )
7579 }
7680
77- attribute , propErr := pSchema .BuildDataSourceAttribute (name , s .GetComputability (name ))
81+ attribute , err := pSchema .BuildDataSourceAttribute (name , s .GetComputability (name ))
7882 if err != nil {
79- return nil , propErr
83+ return nil , err
8084 }
8185
8286 objectAttributes = append (objectAttributes , attribute )
@@ -85,7 +89,11 @@ func (s *OASSchema) BuildDataSourceAttributes() (attrmapper.DataSourceAttributes
8589 return objectAttributes , nil
8690}
8791
88- func (s * OASSchema ) BuildDataSourceAttribute (name string , computability schema.ComputedOptionalRequired ) (attrmapper.DataSourceAttribute , * PropertyError ) {
92+ func (s * OASSchema ) BuildDataSourceAttribute (name string , computability schema.ComputedOptionalRequired ) (attrmapper.DataSourceAttribute , * SchemaError ) {
93+ if util .TerraformIdentifier (name ) == "" {
94+ return nil , s .SchemaErrorFromProperty (fmt .Errorf ("'%s' cannot be converted to a valid Terraform identifier" , name ), name )
95+ }
96+
8997 switch s .Type {
9098 case util .OAS_type_string :
9199 return s .BuildStringDataSource (name , computability )
@@ -103,11 +111,11 @@ func (s *OASSchema) BuildDataSourceAttribute(name string, computability schema.C
103111 }
104112 return s .BuildSingleNestedDataSource (name , computability )
105113 default :
106- return nil , s .NewPropertyError (fmt .Errorf ("invalid schema type '%s'" , s .Type ), name )
114+ return nil , s .SchemaErrorFromProperty (fmt .Errorf ("invalid schema type '%s'" , s .Type ), name )
107115 }
108116}
109117
110- func (s * OASSchema ) BuildProviderAttributes () (attrmapper.ProviderAttributes , * PropertyError ) {
118+ func (s * OASSchema ) BuildProviderAttributes () (attrmapper.ProviderAttributes , * SchemaError ) {
111119 objectAttributes := attrmapper.ProviderAttributes {}
112120
113121 // TODO: throw error if it's not an object?
@@ -119,12 +127,12 @@ func (s *OASSchema) BuildProviderAttributes() (attrmapper.ProviderAttributes, *P
119127 pProxy := s .Schema .Properties [name ]
120128 pSchema , err := BuildSchema (pProxy , SchemaOpts {}, s .GlobalSchemaOpts )
121129 if err != nil {
122- return nil , s .NewPropertyError (err , name )
130+ return nil , s .NestSchemaError (err , name )
123131 }
124132
125- attribute , propErr := pSchema .BuildProviderAttribute (name , s .GetOptionalOrRequired (name ))
133+ attribute , err := pSchema .BuildProviderAttribute (name , s .GetOptionalOrRequired (name ))
126134 if err != nil {
127- return nil , propErr
135+ return nil , err
128136 }
129137
130138 objectAttributes = append (objectAttributes , attribute )
@@ -133,7 +141,11 @@ func (s *OASSchema) BuildProviderAttributes() (attrmapper.ProviderAttributes, *P
133141 return objectAttributes , nil
134142}
135143
136- func (s * OASSchema ) BuildProviderAttribute (name string , optionalOrRequired schema.OptionalRequired ) (attrmapper.ProviderAttribute , * PropertyError ) {
144+ func (s * OASSchema ) BuildProviderAttribute (name string , optionalOrRequired schema.OptionalRequired ) (attrmapper.ProviderAttribute , * SchemaError ) {
145+ if util .TerraformIdentifier (name ) == "" {
146+ return nil , s .SchemaErrorFromProperty (fmt .Errorf ("'%s' cannot be converted to a valid Terraform identifier" , name ), name )
147+ }
148+
137149 switch s .Type {
138150 case util .OAS_type_string :
139151 return s .BuildStringProvider (name , optionalOrRequired )
@@ -151,6 +163,6 @@ func (s *OASSchema) BuildProviderAttribute(name string, optionalOrRequired schem
151163 }
152164 return s .BuildSingleNestedProvider (name , optionalOrRequired )
153165 default :
154- return nil , s .NewPropertyError (fmt .Errorf ("invalid schema type '%s'" , s .Type ), name )
166+ return nil , s .SchemaErrorFromProperty (fmt .Errorf ("invalid schema type '%s'" , s .Type ), name )
155167 }
156168}
0 commit comments