-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathdefault_string.go
More file actions
69 lines (52 loc) · 1.54 KB
/
default_string.go
File metadata and controls
69 lines (52 loc) · 1.54 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
// Copyright IBM Corp. 2023, 2026
// SPDX-License-Identifier: MPL-2.0
package convert
import (
"fmt"
"github.com/hashicorp/terraform-plugin-codegen-spec/code"
specschema "github.com/hashicorp/terraform-plugin-codegen-spec/schema"
generatorschema "github.com/hashicorp/terraform-plugin-codegen-framework/internal/schema"
)
const defaultStringImport = "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
type DefaultString struct {
stringDefault *specschema.StringDefault
}
func NewDefaultString(b *specschema.StringDefault) DefaultString {
return DefaultString{
stringDefault: b,
}
}
func (d DefaultString) Equal(other DefaultString) bool {
return d.stringDefault.Equal(other.stringDefault)
}
func (d DefaultString) Imports() *generatorschema.Imports {
imports := generatorschema.NewImports()
if d.stringDefault == nil {
return imports
}
if d.stringDefault.Static != nil {
imports.Add(code.Import{
Path: defaultStringImport,
})
}
if d.stringDefault.Custom != nil {
for _, i := range d.stringDefault.Custom.Imports {
if len(i.Path) > 0 {
imports.Add(i)
}
}
}
return imports
}
func (d DefaultString) Schema() []byte {
if d.stringDefault == nil {
return nil
}
if d.stringDefault.Static != nil {
return []byte(fmt.Sprintf("Default: stringdefault.StaticString(%q),\n", *d.stringDefault.Static))
}
if d.stringDefault.Custom != nil && d.stringDefault.Custom.SchemaDefinition != "" {
return []byte(fmt.Sprintf("Default: %s,\n", d.stringDefault.Custom.SchemaDefinition))
}
return nil
}