-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathstring.go
More file actions
91 lines (70 loc) · 2.32 KB
/
string.go
File metadata and controls
91 lines (70 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright IBM Corp. 2023, 2025
// SPDX-License-Identifier: MPL-2.0
package attrmapper
import (
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer"
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util"
"github.com/hashicorp/terraform-plugin-codegen-spec/datasource"
"github.com/hashicorp/terraform-plugin-codegen-spec/provider"
"github.com/hashicorp/terraform-plugin-codegen-spec/resource"
)
type ResourceStringAttribute struct {
resource.StringAttribute
Name string
}
func (a *ResourceStringAttribute) GetName() string {
return a.Name
}
func (a *ResourceStringAttribute) Merge(mergeAttribute ResourceAttribute) (ResourceAttribute, error) {
stringAttribute, ok := mergeAttribute.(*ResourceStringAttribute)
// TODO: return error if types don't match?
if ok && (a.Description == nil || *a.Description == "") {
a.Description = stringAttribute.Description
}
return a, nil
}
func (a *ResourceStringAttribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) {
a.Description = &override.Description
return a, nil
}
func (a *ResourceStringAttribute) ToSpec() resource.Attribute {
return resource.Attribute{
Name: util.TerraformIdentifier(a.Name),
String: &a.StringAttribute,
}
}
type DataSourceStringAttribute struct {
datasource.StringAttribute
Name string
}
func (a *DataSourceStringAttribute) GetName() string {
return a.Name
}
func (a *DataSourceStringAttribute) Merge(mergeAttribute DataSourceAttribute) (DataSourceAttribute, error) {
stringAttribute, ok := mergeAttribute.(*DataSourceStringAttribute)
// TODO: return error if types don't match?
if ok && (a.Description == nil || *a.Description == "") {
a.Description = stringAttribute.Description
}
return a, nil
}
func (a *DataSourceStringAttribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) {
a.Description = &override.Description
return a, nil
}
func (a *DataSourceStringAttribute) ToSpec() datasource.Attribute {
return datasource.Attribute{
Name: util.TerraformIdentifier(a.Name),
String: &a.StringAttribute,
}
}
type ProviderStringAttribute struct {
provider.StringAttribute
Name string
}
func (a *ProviderStringAttribute) ToSpec() provider.Attribute {
return provider.Attribute{
Name: util.TerraformIdentifier(a.Name),
String: &a.StringAttribute,
}
}