Skip to content

Commit afe1725

Browse files
authored
Initial OAS deprecated property support (#41)
Reference: #32 Sets a default `This attribute is deprecated.` message but left room for it to be overridden in the future.
1 parent b13fffc commit afe1725

19 files changed

+967
-47
lines changed

DESIGN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ If not required, or if the field is in a different schema than the `Read` operat
164164
| Field (OAS) | Field (Plugin Framework Schema) |
165165
|-------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
166166
| [default](https://json-schema.org/draft/2020-12/json-schema-validation.html#name-default) | [(Attribute).Default](https://developer.hashicorp.com/terraform/plugin/framework/resources/default) (resources only) |
167+
| [deprecated](https://json-schema.org/draft/2020-12/json-schema-validation.html#name-deprecated) | [(Attribute).DeprecationMessage](https://developer.hashicorp.com/terraform/plugin/framework/deprecations) |
167168
| [description](https://spec.openapis.org/oas/latest.html#rich-text-formatting) | [(Attribute).MarkdownDescription](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#markdowndescription-1) |
168169
| [enum](https://json-schema.org/draft/2020-12/json-schema-validation.html#name-enum) | [(Attribute).Validators](https://developer.hashicorp.com/terraform/plugin/framework/validation) |
169170
| [format (password)](https://spec.openapis.org/oas/latest.html#data-types) | [(StringAttribute).Sensitive](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/schemas#sensitive) |

internal/cmd/testdata/github/generated_framework_ir.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,7 @@
23542354
"name": "use_squash_pr_title_as_default",
23552355
"bool": {
23562356
"computed_optional_required": "computed_optional",
2357+
"deprecation_message": "This attribute is deprecated.",
23572358
"description": "Whether a squash merge commit can use the pull request title as default. **This property has been deprecated. Please use `squash_merge_commit_title` instead."
23582359
}
23592360
},
@@ -4241,6 +4242,7 @@
42414242
"name": "use_squash_pr_title_as_default",
42424243
"bool": {
42434244
"computed_optional_required": "computed_optional",
4245+
"deprecation_message": "This attribute is deprecated.",
42444246
"description": "Whether a squash merge commit can use the pull request title as default. **This property has been deprecated. Please use `squash_merge_commit_title` instead."
42454247
}
42464248
},
@@ -6077,6 +6079,7 @@
60776079
"name": "use_squash_pr_title_as_default",
60786080
"bool": {
60796081
"computed_optional_required": "computed_optional",
6082+
"deprecation_message": "This attribute is deprecated.",
60806083
"description": "Whether a squash merge commit can use the pull request title as default. **This property has been deprecated. Please use `squash_merge_commit_title` instead."
60816084
}
60826085
},
@@ -8941,6 +8944,7 @@
89418944
"default": {
89428945
"static": false
89438946
},
8947+
"deprecation_message": "This attribute is deprecated.",
89448948
"description": "Whether a squash merge commit can use the pull request title as default. **This property has been deprecated. Please use `squash_merge_commit_title` instead."
89458949
}
89468950
},
@@ -10753,6 +10757,7 @@
1075310757
"default": {
1075410758
"static": false
1075510759
},
10760+
"deprecation_message": "This attribute is deprecated.",
1075610761
"description": "Whether a squash merge commit can use the pull request title as default. **This property has been deprecated. Please use `squash_merge_commit_title` instead."
1075710762
}
1075810763
},
@@ -12622,6 +12627,7 @@
1262212627
"default": {
1262312628
"static": false
1262412629
},
12630+
"deprecation_message": "This attribute is deprecated.",
1262512631
"description": "Whether a squash merge commit can use the pull request title as default. **This property has been deprecated. Please use `squash_merge_commit_title` instead."
1262612632
}
1262712633
},

internal/cmd/testdata/scaleway/generated_framework_ir.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
}
186186
}
187187
],
188+
"deprecation_message": "This attribute is deprecated.",
188189
"description": "The server bootscript."
189190
}
190191
},
@@ -385,6 +386,7 @@
385386
"name": "export_uri",
386387
"string": {
387388
"computed_optional_required": "computed_optional",
389+
"deprecation_message": "This attribute is deprecated.",
388390
"description": "Show the volume NBD export URI."
389391
}
390392
},
@@ -1455,6 +1457,7 @@
14551457
}
14561458
}
14571459
],
1460+
"deprecation_message": "This attribute is deprecated.",
14581461
"description": "The server bootscript."
14591462
}
14601463
},
@@ -1655,6 +1658,7 @@
16551658
"name": "export_uri",
16561659
"string": {
16571660
"computed_optional_required": "computed_optional",
1661+
"deprecation_message": "This attribute is deprecated.",
16581662
"description": "Show the volume NBD export URI."
16591663
}
16601664
},
@@ -2475,6 +2479,7 @@
24752479
"name": "default_bootscript",
24762480
"string": {
24772481
"computed_optional_required": "computed_optional",
2482+
"deprecation_message": "This attribute is deprecated.",
24782483
"description": "Default bootscript of the image."
24792484
}
24802485
},
@@ -2506,6 +2511,7 @@
25062511
"name": "organization",
25072512
"string": {
25082513
"computed_optional_required": "computed_optional",
2514+
"deprecation_message": "This attribute is deprecated.",
25092515
"description": "Organization ID of the volume."
25102516
}
25112517
},
@@ -2563,6 +2569,7 @@
25632569
"name": "organization",
25642570
"string": {
25652571
"computed_optional_required": "computed_optional",
2572+
"deprecation_message": "This attribute is deprecated.",
25662573
"description": "Organization ID of the image."
25672574
}
25682575
},
@@ -2758,6 +2765,7 @@
27582765
"name": "export_uri",
27592766
"string": {
27602767
"computed_optional_required": "computed_optional",
2768+
"deprecation_message": "This attribute is deprecated.",
27612769
"description": "Show the volume NBD export URI."
27622770
}
27632771
},
@@ -3058,6 +3066,7 @@
30583066
"name": "organization",
30593067
"string": {
30603068
"computed_optional_required": "computed_optional",
3069+
"deprecation_message": "This attribute is deprecated.",
30613070
"description": "The organization ID the IP is reserved in."
30623071
}
30633072
},

internal/mapper/oas/bool.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func (s *OASSchema) BuildBoolResource(name string, computability schema.Computed
1515
Name: name,
1616
Bool: &resource.BoolAttribute{
1717
ComputedOptionalRequired: computability,
18+
DeprecationMessage: s.GetDeprecationMessage(),
1819
Description: s.GetDescription(),
1920
},
2021
}
@@ -37,6 +38,7 @@ func (s *OASSchema) BuildBoolDataSource(name string, computability schema.Comput
3738
Name: name,
3839
Bool: &datasource.BoolAttribute{
3940
ComputedOptionalRequired: computability,
41+
DeprecationMessage: s.GetDeprecationMessage(),
4042
Description: s.GetDescription(),
4143
},
4244
}
@@ -48,8 +50,9 @@ func (s *OASSchema) BuildBoolProvider(name string, optionalOrRequired schema.Opt
4850
return &provider.Attribute{
4951
Name: name,
5052
Bool: &provider.BoolAttribute{
51-
OptionalRequired: optionalOrRequired,
52-
Description: s.GetDescription(),
53+
OptionalRequired: optionalOrRequired,
54+
DeprecationMessage: s.GetDeprecationMessage(),
55+
Description: s.GetDescription(),
5356
},
5457
}, nil
5558
}

internal/mapper/oas/bool_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ func TestBuildBoolResource(t *testing.T) {
9090
},
9191
},
9292
},
93+
"boolean attributes deprecated": {
94+
schema: &base.Schema{
95+
Type: []string{"object"},
96+
Properties: map[string]*base.SchemaProxy{
97+
"bool_prop": base.CreateSchemaProxy(&base.Schema{
98+
Type: []string{"boolean"},
99+
Deprecated: pointer(true),
100+
}),
101+
},
102+
},
103+
expectedAttributes: &[]resource.Attribute{
104+
{
105+
Name: "bool_prop",
106+
Bool: &resource.BoolAttribute{
107+
ComputedOptionalRequired: schema.ComputedOptional,
108+
DeprecationMessage: pointer("This attribute is deprecated."),
109+
},
110+
},
111+
},
112+
},
93113
"list attributes with bool element type": {
94114
schema: &base.Schema{
95115
Type: []string{"object"},
@@ -198,6 +218,26 @@ func TestBuildBoolDataSource(t *testing.T) {
198218
},
199219
},
200220
},
221+
"boolean attributes deprecated": {
222+
schema: &base.Schema{
223+
Type: []string{"object"},
224+
Properties: map[string]*base.SchemaProxy{
225+
"bool_prop": base.CreateSchemaProxy(&base.Schema{
226+
Type: []string{"boolean"},
227+
Deprecated: pointer(true),
228+
}),
229+
},
230+
},
231+
expectedAttributes: &[]datasource.Attribute{
232+
{
233+
Name: "bool_prop",
234+
Bool: &datasource.BoolAttribute{
235+
ComputedOptionalRequired: schema.ComputedOptional,
236+
DeprecationMessage: pointer("This attribute is deprecated."),
237+
},
238+
},
239+
},
240+
},
201241
"list attributes with bool element type": {
202242
schema: &base.Schema{
203243
Type: []string{"object"},
@@ -306,6 +346,26 @@ func TestBuildBoolProvider(t *testing.T) {
306346
},
307347
},
308348
},
349+
"boolean attributes deprecated": {
350+
schema: &base.Schema{
351+
Type: []string{"object"},
352+
Properties: map[string]*base.SchemaProxy{
353+
"bool_prop": base.CreateSchemaProxy(&base.Schema{
354+
Type: []string{"boolean"},
355+
Deprecated: pointer(true),
356+
}),
357+
},
358+
},
359+
expectedAttributes: &[]provider.Attribute{
360+
{
361+
Name: "bool_prop",
362+
Bool: &provider.BoolAttribute{
363+
OptionalRequired: schema.Optional,
364+
DeprecationMessage: pointer("This attribute is deprecated."),
365+
},
366+
},
367+
},
368+
},
309369
"list attributes with bool element type": {
310370
schema: &base.Schema{
311371
Type: []string{"object"},

internal/mapper/oas/collection.go

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (s *OASSchema) BuildCollectionResource(name string, computability schema.Co
4141
Attributes: *objectAttributes,
4242
},
4343
ComputedOptionalRequired: computability,
44+
DeprecationMessage: s.GetDeprecationMessage(),
4445
Description: s.GetDescription(),
4546
}
4647

@@ -56,6 +57,7 @@ func (s *OASSchema) BuildCollectionResource(name string, computability schema.Co
5657
Attributes: *objectAttributes,
5758
},
5859
ComputedOptionalRequired: computability,
60+
DeprecationMessage: s.GetDeprecationMessage(),
5961
Description: s.GetDescription(),
6062
}
6163

@@ -75,6 +77,7 @@ func (s *OASSchema) BuildCollectionResource(name string, computability schema.Co
7577
result.Set = &resource.SetAttribute{
7678
ElementType: elemType,
7779
ComputedOptionalRequired: computability,
80+
DeprecationMessage: s.GetDeprecationMessage(),
7881
Description: s.GetDescription(),
7982
}
8083

@@ -88,6 +91,7 @@ func (s *OASSchema) BuildCollectionResource(name string, computability schema.Co
8891
result.List = &resource.ListAttribute{
8992
ElementType: elemType,
9093
ComputedOptionalRequired: computability,
94+
DeprecationMessage: s.GetDeprecationMessage(),
9195
Description: s.GetDescription(),
9296
}
9397

@@ -125,6 +129,7 @@ func (s *OASSchema) BuildCollectionDataSource(name string, computability schema.
125129
Attributes: *objectAttributes,
126130
},
127131
ComputedOptionalRequired: computability,
132+
DeprecationMessage: s.GetDeprecationMessage(),
128133
Description: s.GetDescription(),
129134
}
130135

@@ -140,6 +145,7 @@ func (s *OASSchema) BuildCollectionDataSource(name string, computability schema.
140145
Attributes: *objectAttributes,
141146
},
142147
ComputedOptionalRequired: computability,
148+
DeprecationMessage: s.GetDeprecationMessage(),
143149
Description: s.GetDescription(),
144150
}
145151

@@ -159,6 +165,7 @@ func (s *OASSchema) BuildCollectionDataSource(name string, computability schema.
159165
result.Set = &datasource.SetAttribute{
160166
ElementType: elemType,
161167
ComputedOptionalRequired: computability,
168+
DeprecationMessage: s.GetDeprecationMessage(),
162169
Description: s.GetDescription(),
163170
}
164171

@@ -172,6 +179,7 @@ func (s *OASSchema) BuildCollectionDataSource(name string, computability schema.
172179
result.List = &datasource.ListAttribute{
173180
ElementType: elemType,
174181
ComputedOptionalRequired: computability,
182+
DeprecationMessage: s.GetDeprecationMessage(),
175183
Description: s.GetDescription(),
176184
}
177185

@@ -208,25 +216,25 @@ func (s *OASSchema) BuildCollectionProvider(name string, optionalOrRequired sche
208216
NestedObject: provider.NestedAttributeObject{
209217
Attributes: *objectAttributes,
210218
},
211-
OptionalRequired: optionalOrRequired,
212-
Description: s.GetDescription(),
219+
OptionalRequired: optionalOrRequired,
220+
DeprecationMessage: s.GetDeprecationMessage(),
221+
Description: s.GetDescription(),
222+
Validators: s.GetSetValidators(),
213223
}
214224

215-
result.SetNested.Validators = s.GetSetValidators()
216-
217225
return result, nil
218226
}
219227

220228
result.ListNested = &provider.ListNestedAttribute{
221229
NestedObject: provider.NestedAttributeObject{
222230
Attributes: *objectAttributes,
223231
},
224-
OptionalRequired: optionalOrRequired,
225-
Description: s.GetDescription(),
232+
OptionalRequired: optionalOrRequired,
233+
DeprecationMessage: s.GetDeprecationMessage(),
234+
Description: s.GetDescription(),
235+
Validators: s.GetListValidators(),
226236
}
227237

228-
result.ListNested.Validators = s.GetListValidators()
229-
230238
return result, nil
231239
}
232240

@@ -237,24 +245,24 @@ func (s *OASSchema) BuildCollectionProvider(name string, optionalOrRequired sche
237245

238246
if s.Schema.Format == util.TF_format_set {
239247
result.Set = &provider.SetAttribute{
240-
ElementType: elemType,
241-
OptionalRequired: optionalOrRequired,
242-
Description: s.GetDescription(),
248+
ElementType: elemType,
249+
OptionalRequired: optionalOrRequired,
250+
DeprecationMessage: s.GetDeprecationMessage(),
251+
Description: s.GetDescription(),
252+
Validators: s.GetSetValidators(),
243253
}
244254

245-
result.Set.Validators = s.GetSetValidators()
246-
247255
return result, nil
248256
}
249257

250258
result.List = &provider.ListAttribute{
251-
ElementType: elemType,
252-
OptionalRequired: optionalOrRequired,
253-
Description: s.GetDescription(),
259+
ElementType: elemType,
260+
OptionalRequired: optionalOrRequired,
261+
DeprecationMessage: s.GetDeprecationMessage(),
262+
Description: s.GetDescription(),
263+
Validators: s.GetListValidators(),
254264
}
255265

256-
result.List.Validators = s.GetListValidators()
257-
258266
return result, nil
259267
}
260268

0 commit comments

Comments
 (0)