@@ -11,7 +11,7 @@ import (
11
11
"github.com/hashicorp/terraform-plugin-codegen-spec/schema"
12
12
)
13
13
14
- func (s * OASSchema ) BuildResourceAttributes () (attrmapper.ResourceAttributes , * PropertyError ) {
14
+ func (s * OASSchema ) BuildResourceAttributes () (attrmapper.ResourceAttributes , * SchemaError ) {
15
15
objectAttributes := attrmapper.ResourceAttributes {}
16
16
17
17
// TODO: throw error if it's not an object?
@@ -23,12 +23,12 @@ func (s *OASSchema) BuildResourceAttributes() (attrmapper.ResourceAttributes, *P
23
23
pProxy := s .Schema .Properties [name ]
24
24
pSchema , err := BuildSchema (pProxy , SchemaOpts {}, s .GlobalSchemaOpts )
25
25
if err != nil {
26
- return nil , s .NewPropertyError (err , name )
26
+ return nil , s .NestSchemaError (err , name )
27
27
}
28
28
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
32
32
}
33
33
34
34
objectAttributes = append (objectAttributes , attribute )
@@ -37,7 +37,11 @@ func (s *OASSchema) BuildResourceAttributes() (attrmapper.ResourceAttributes, *P
37
37
return objectAttributes , nil
38
38
}
39
39
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
+
41
45
switch s .Type {
42
46
case util .OAS_type_string :
43
47
return s .BuildStringResource (name , computability )
@@ -55,11 +59,11 @@ func (s *OASSchema) BuildResourceAttribute(name string, computability schema.Com
55
59
}
56
60
return s .BuildSingleNestedResource (name , computability )
57
61
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 )
59
63
}
60
64
}
61
65
62
- func (s * OASSchema ) BuildDataSourceAttributes () (attrmapper.DataSourceAttributes , * PropertyError ) {
66
+ func (s * OASSchema ) BuildDataSourceAttributes () (attrmapper.DataSourceAttributes , * SchemaError ) {
63
67
objectAttributes := attrmapper.DataSourceAttributes {}
64
68
65
69
// TODO: throw error if it's not an object?
@@ -71,12 +75,12 @@ func (s *OASSchema) BuildDataSourceAttributes() (attrmapper.DataSourceAttributes
71
75
pProxy := s .Schema .Properties [name ]
72
76
pSchema , err := BuildSchema (pProxy , SchemaOpts {}, s .GlobalSchemaOpts )
73
77
if err != nil {
74
- return nil , s .NewPropertyError (err , name )
78
+ return nil , s .NestSchemaError (err , name )
75
79
}
76
80
77
- attribute , propErr := pSchema .BuildDataSourceAttribute (name , s .GetComputability (name ))
81
+ attribute , err := pSchema .BuildDataSourceAttribute (name , s .GetComputability (name ))
78
82
if err != nil {
79
- return nil , propErr
83
+ return nil , err
80
84
}
81
85
82
86
objectAttributes = append (objectAttributes , attribute )
@@ -85,7 +89,11 @@ func (s *OASSchema) BuildDataSourceAttributes() (attrmapper.DataSourceAttributes
85
89
return objectAttributes , nil
86
90
}
87
91
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
+
89
97
switch s .Type {
90
98
case util .OAS_type_string :
91
99
return s .BuildStringDataSource (name , computability )
@@ -103,11 +111,11 @@ func (s *OASSchema) BuildDataSourceAttribute(name string, computability schema.C
103
111
}
104
112
return s .BuildSingleNestedDataSource (name , computability )
105
113
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 )
107
115
}
108
116
}
109
117
110
- func (s * OASSchema ) BuildProviderAttributes () (attrmapper.ProviderAttributes , * PropertyError ) {
118
+ func (s * OASSchema ) BuildProviderAttributes () (attrmapper.ProviderAttributes , * SchemaError ) {
111
119
objectAttributes := attrmapper.ProviderAttributes {}
112
120
113
121
// TODO: throw error if it's not an object?
@@ -119,12 +127,12 @@ func (s *OASSchema) BuildProviderAttributes() (attrmapper.ProviderAttributes, *P
119
127
pProxy := s .Schema .Properties [name ]
120
128
pSchema , err := BuildSchema (pProxy , SchemaOpts {}, s .GlobalSchemaOpts )
121
129
if err != nil {
122
- return nil , s .NewPropertyError (err , name )
130
+ return nil , s .NestSchemaError (err , name )
123
131
}
124
132
125
- attribute , propErr := pSchema .BuildProviderAttribute (name , s .GetOptionalOrRequired (name ))
133
+ attribute , err := pSchema .BuildProviderAttribute (name , s .GetOptionalOrRequired (name ))
126
134
if err != nil {
127
- return nil , propErr
135
+ return nil , err
128
136
}
129
137
130
138
objectAttributes = append (objectAttributes , attribute )
@@ -133,7 +141,11 @@ func (s *OASSchema) BuildProviderAttributes() (attrmapper.ProviderAttributes, *P
133
141
return objectAttributes , nil
134
142
}
135
143
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
+
137
149
switch s .Type {
138
150
case util .OAS_type_string :
139
151
return s .BuildStringProvider (name , optionalOrRequired )
@@ -151,6 +163,6 @@ func (s *OASSchema) BuildProviderAttribute(name string, optionalOrRequired schem
151
163
}
152
164
return s .BuildSingleNestedProvider (name , optionalOrRequired )
153
165
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 )
155
167
}
156
168
}
0 commit comments